Module: Scorched::DynamicDelegate
- Included in:
- Collection, Options
- Defined in:
- lib/scorched/dynamic_delegate.rb
Overview
Unlike most delegator’s that delegate to an object, this delegator delegates to a runtime expression, and so the target object can be dynamic.
Instance Method Summary collapse
Instance Method Details
#alias_each(methods) ⇒ Object
16 17 18 19 20 |
# File 'lib/scorched/dynamic_delegate.rb', line 16 def alias_each(methods) methods.each do |m| alias_method yield(m), m end end |
#delegate(target_literal, *methods) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/scorched/dynamic_delegate.rb', line 5 def delegate(target_literal, *methods) methods.each do |method| method = method.to_sym class_eval <<-CODE def #{method}(*args, &block) #{target_literal}.__send__(#{method.inspect}, *args, &block) end CODE end end |