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] && "#{options[:prefix] == true ? to : options[:prefix]}_" with = [:with] || [] methods.each do |method| module_eval(" def \#{prefix}\#{method}(*args, &block)\n args += [\#{with * \", \"}]\n \#{to}.__send__(\#{method.inspect}, *args, &block)\n end\n EOS\n end\nend\n", "(__DELEGATION__)", 1) |