instiki/vendor/rails/activesupport/lib/active_support/core_ext/module/delegation.rb

16 lines
432 B
Ruby
Raw Normal View History

2007-01-22 14:43:50 +01:00
class Module
def delegate(*methods)
options = methods.pop
unless options.is_a?(Hash) && to = options[:to]
raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key"
end
methods.each do |method|
module_eval(<<-EOS, "(__DELEGATION__)", 1)
def #{method}(*args, &block)
#{to}.__send__(#{method.inspect}, *args, &block)
end
EOS
end
end
end