Module: Reac::Reactivize
- Defined in:
- lib/reac/reactivize.rb
Constant Summary collapse
- OLD_NAME =
{ :+ => "plus", :- => "minus", :* => "mul", :/ => "div" }
Instance Method Summary collapse
- #reactivize(*methods) ⇒ Object
-
#reactivize_singleton(*methods) ⇒ Object
reactivize singleton methods.
Instance Method Details
#reactivize(*methods) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/reac/reactivize.rb', line 26 def reactivize(*methods) methods.each do |m| old_name = OLD_NAME[m] || m module_eval <<-EOD alias __old_#{old_name}__ #{m} def #{m}(arg) if arg.kind_of?(Reac) Reac(self).#{m}(arg) else __old_#{old_name}__(arg) end end EOD end end |
#reactivize_singleton(*methods) ⇒ Object
reactivize singleton methods.
example:
module Math
reactivize_singleton :sin, :cos
end
48 49 50 51 52 53 54 55 |
# File 'lib/reac/reactivize.rb', line 48 def reactivize_singleton(*methods) method_list = methods.map{|m|m.inspect}.join(',') instance_eval <<-EOD class << self reactivize #{method_list} end EOD end |