Class: Enumerable::Proxy

Inherits:
Object show all
Defined in:
lib/rext/enumerable/helpers.rb

Overview

Proxy

The enumerable proxy class is utilized to allow methods such as #group_by, #map, and others to provide a method call alternative to a block.

For example words.group_by { |word| word.length } can be replaced by words.group_by_.length

See

  • Enumerable#proxy

Instance Method Summary collapse

Constructor Details

#initialize(object, meth) ⇒ Proxy

Returns a new instance of Proxy.



25
26
27
# File 'lib/rext/enumerable/helpers.rb', line 25

def initialize object, meth
  @object, @method = object, meth
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



29
30
31
# File 'lib/rext/enumerable/helpers.rb', line 29

def method_missing meth, *args, &block
  @object.__send__(@method) { |o| o.__send__(meth, *args, &block) }
end