Class: Module

Inherits:
Object show all
Defined in:
lib/core_ext/module.rb

Instance Method Summary collapse

Instance Method Details

#delegate(*methods) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/core_ext/module.rb', line 2

def delegate(*methods)
  options = methods.pop
  raise ArgumentError, "Delegation needs a target." unless options.is_a?(Hash) && to = options[:to]

  methods.each do |method|
    module_eval("      def \#{method}(*args, &block)\n        \#{to}.__send__(\#{method.inspect}, *args, &block)\n      end\n    EOS\n  end\nend\n", "(__DELEGATION__)", 1)