Class: Enumerable::Elementor

Inherits:
Object
  • Object
show all
Defined in:
lib/more/facets/elementor.rb

Overview

Elementor

Elementor is a type of functor. Operations applied to it are routed to each element.

Instance Method Summary collapse

Constructor Details

#initialize(elem_object, elem_method = nil) ⇒ Elementor

Returns a new instance of Elementor.



183
184
185
186
# File 'lib/more/facets/elementor.rb', line 183

def initialize(elem_object, elem_method=nil)
  @elem_object = elem_object
  @elem_method = elem_method || :map
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

def ==(other)

instance_delegate == other.instance_delegate &&
instance_operator == other.instance_operator

end



201
202
203
# File 'lib/more/facets/elementor.rb', line 201

def method_missing(sym,*args,&blk)
  @elem_object.send(@elem_method){ |x| x.send(sym,*args,&blk) }
end

Instance Method Details

#instance_delegateObject



188
189
190
# File 'lib/more/facets/elementor.rb', line 188

def instance_delegate
  @elem_object
end

#instance_operatorObject



192
193
194
# File 'lib/more/facets/elementor.rb', line 192

def instance_operator
  @elem_method
end