Sha256: efff727308dd6c1a0e67e764cdcae1c84e66ca6a2e819e562b451d984e425be9

Contents?: true

Size: 432 Bytes

Versions: 2

Compression:

Stored size: 432 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activesupport-1.3.0 lib/active_support/core_ext/module/delegation.rb
activesupport-1.3.1 lib/active_support/core_ext/module/delegation.rb