Sha256: 3aa35c5f5664403f2f220eae44ce8a79e74e8b802563255d1cfb457d6ea00b9e
Contents?: true
Size: 744 Bytes
Versions: 14
Compression:
Stored size: 744 Bytes
Contents
class Module # Modified version from ActiveSupport to support :with (for additional arguments) 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 as the last argument (e.g. delegate :hello, :to => :greeter)." end prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_" with = options[: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 end
Version data entries
14 entries across 14 versions & 3 rubygems