Module: Rucas::Extensions
- Defined in:
- lib/rucas/extensions.rb
Constant Summary collapse
- PATCH_HASH =
Avoid collisions with other patches; this maps operators (+,-, etc.) to normal method names, so they can be called without the additional overhead of Kernel#send.
Hash.new {|h,k| k}
Class Method Summary collapse
-
.apply ⇒ Object
Patch system classes to make constants work with vars (e.g. 0 + x).
-
.unapply ⇒ Object
Get rid of patches.
-
.with_rucas_name(original) ⇒ Object
See PATCH_HASH.
-
.without_rucas_name(original) ⇒ Object
See PATCH_HASH.
Class Method Details
.apply ⇒ Object
Patch system classes to make constants work with vars (e.g. 0 + x).
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rucas/extensions.rb', line 68 def self.apply for c in Symbolic::CONST_CLASSES for op in Symbolic::BINARY_OPS.keys c.class_eval %Q{ alias_method :#{without_rucas_name(op)}, :#{op} alias_method :#{op}, :#{with_rucas_name(op)} } end c.module_eval do alias_method :method_missing_without_rucas, :method_missing alias_method :method_missing, :method_missing_with_rucas end end end |
.unapply ⇒ Object
Get rid of patches.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rucas/extensions.rb', line 84 def self.unapply for c in Symbolic::CONST_CLASSES for op in Symbolic::BINARY_OPS.keys c.class_eval %Q{ alias_method :#{with_rucas_name(op)}, :#{op} alias_method :#{op}, :#{without_rucas_name(op)} } end c.module_eval do alias_method :method_missing_with_rucas, :method_missing alias_method :method_missing, :method_missing_without_rucas end end end |
.with_rucas_name(original) ⇒ Object
See PATCH_HASH.
32 33 34 |
# File 'lib/rucas/extensions.rb', line 32 def self.with_rucas_name original "#{PATCH_HASH[original]}__with_rucas" end |
.without_rucas_name(original) ⇒ Object
See PATCH_HASH.
27 28 29 |
# File 'lib/rucas/extensions.rb', line 27 def self.without_rucas_name original "#{PATCH_HASH[original]}__without_rucas" end |