Sha256: 7e7700219c8d37bc4348bc9941f4bf6295af1786ccde549a502fd30bc5c178a2

Contents?: true

Size: 571 Bytes

Versions: 3

Compression:

Stored size: 571 Bytes

Contents

class Module
  def delegate_to(object, *collection)
    collection = [*collection]
    is_hash = ((collection.size == 1) and collection.first.kind_of?(Hash))
    hash = is_hash ? collection.first : nil
  
    delegate_to_method = lambda do |as, method|
      module_eval() do
        define_method(as) do |*args|
          send(object).send(method, *args)
        end
      end
    end
  
    if hash
      hash.each { |as, method| delegate_to_method.call(as, method) }
    else
      collection.each { |method| delegate_to_method.call(method, method) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radiant-0.5.0 lib/advanced_delegation.rb
radiant-0.5.1 lib/advanced_delegation.rb
radiant-0.5.2 lib/advanced_delegation.rb