Sha256: 97768f92747420d99c2fee4275599c389ce01272dd8ee37c18b80491d125e6fd

Contents?: true

Size: 620 Bytes

Versions: 7

Compression:

Stored size: 620 Bytes

Contents

== Hash#recursively

  require 'facets/hash/recursively'

  h = {:a=>1, :b=>{:c=>3}}

Without a block passed tot he #recursive method, the block passed to the
enumeratig method will be used for both recursive and non-recursive yields.

  r = h.recursively.map{ |k,v| [k.to_s, v] }

  r.assert == [['a', 1], ['b', [['c', 3]]]]

But if we pass a block to #recursive we can treat the recusive yield 
separately, which in turn allows us to manipulate the non-recursive
yields with a different procedure.

  r = h.recursively{ |k,v| [k.to_s, v] }.map{ |k,v| [k.to_s,v.to_s] }

  r.assert == [['a','1'], ['b', [['c', '3']]]]

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
facets-3.0.0 demo/core/hash/recursively.rdoc
facets-2.9.3 qed/core/hash/recursively.rdoc
facets-2.9.2 qed/core/hash/recursively.rdoc
facets-2.9.1 qed/core/hash/recursively.rdoc
facets-2.9.0 qed/core/hash/recursively.rdoc
facets-2.9.0.pre.2 qed/core/hash/recursively.rdoc
facets-2.9.0.pre.1 qed/core/hash/recursively.rdoc