Class: Hash::ComparingRecursor
- Inherits:
-
Enumerable::Recursor
- Object
- Enumerable::Recursor
- Hash::ComparingRecursor
- Defined in:
- lib/facets/hash/recursively_comparing.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(enum, other_enum, *types, &block) ⇒ ComparingRecursor
constructor
A new instance of ComparingRecursor.
- #method_missing(op, &yld) ⇒ Object
Constructor Details
#initialize(enum, other_enum, *types, &block) ⇒ ComparingRecursor
Returns a new instance of ComparingRecursor.
9 10 11 12 |
# File 'lib/facets/hash/recursively_comparing.rb', line 9 def initialize(enum, other_enum, *types, &block) @other_enum = other_enum super(enum, *types, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(op, &yld) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/facets/hash/recursively_comparing.rb', line 13 def method_missing(op, &yld) yld = yld || lambda{ |k,v| [k,v] } # ? to_enum rec = @block || yld #lambda{ |k,v| [k,v] } @enum.__send__(op) do |k,v| other_v = @other_enum.dig(k) #puts %(#{@enum.inspect}: k=#{k.inspect}, v=#{v.inspect}, other_v=#{other_v.inspect}) case v when String # b/c of 1.8 yld.call(k, v, other_v) when *@types res = v.recursively_comparing(other_v, &@block).__send__(op,&yld) rec.call(k, res, other_v) else yld.call(k, v, other_v) end end end |