Class: Hash::Recursor

Inherits:
Enumerable::Recursor show all
Defined in:
lib/core/facets/hash/recursively.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Enumerable::Recursor

#initialize

Constructor Details

This class inherits a constructor from Enumerable::Recursor

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(op, &yld) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/core/facets/hash/recursively.rb', line 25

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|
    case v
    when String # b/c of 1.8
      yld.call(k,v)
    when *@types
      res = v.recursively(*@types, &@block).__send__(op,&yld)
      rec.call(k, res)
    else
      yld.call(k,v)
    end
  end
end