Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/switchboard/ext/delegate.rb
Instance Method Summary collapse
-
#delegate(*methods) ⇒ Object
Modified version from ActiveSupport to support :with (for additional arguments).
Instance Method Details
#delegate(*methods) ⇒ Object
Modified version from ActiveSupport to support :with (for additional arguments)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/switchboard/ext/delegate.rb', line 3 def delegate(*methods) = methods.pop unless .is_a?(Hash) && to = [:to] raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)." end prefix = [:prefix] && "#{[:prefix] == true ? to : [:prefix]}_" with = [:with] || [] methods.each do |method| module_eval(<<-EOS, "(__DELEGATION__)", 1) def #{prefix}#{method}(*args, &block) args += [#{with * ", "}] #{to}.__send__(#{method.inspect}, *args, &block) end EOS end end |