Class: Enumerable::Permeator

Inherits:
Object
  • Object
show all
Defined in:
lib/core/facets/enumerable/per.rb

Overview

Permeator is a Functor for operating over each element of an Enumearble. (Note: This used to be called an Elementor.)

TODO: With Ruby 1.9+ this would not be required, as it can be replaced by a generic Functor, becuase then lambda definitions can pass blocks.

Instance Method Summary collapse

Constructor Details

#initialize(enum_object, enum_method = nil, *enum_args) ⇒ Permeator

Returns a new instance of Permeator.



38
39
40
41
42
# File 'lib/core/facets/enumerable/per.rb', line 38

def initialize(enum_object, enum_method=nil, *enum_args)
  @enum_object = enum_object
  @enum_method = enum_method || :map
  @enum_args   = enum_args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blk) ⇒ Object



52
53
54
# File 'lib/core/facets/enumerable/per.rb', line 52

def method_missing(sym, *args, &blk)
  @enum_object.__send__(@enum_method){ |x| x.__send__(sym, *args, &blk) }
end

Instance Method Details

#instance_delegateObject



44
45
46
# File 'lib/core/facets/enumerable/per.rb', line 44

def instance_delegate
  @enum_object
end

#instance_operatorObject



48
49
50
# File 'lib/core/facets/enumerable/per.rb', line 48

def instance_operator
  @enum_method
end