Skip to content

ktlacaelel/walkash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

walkash

Walks nested hashes giving you the power to interact with its inner parts.

Usage

kazu@utopia:~/dev/git/walkash$ cat examples/walk_hash.rb

require 'rubygems'
require 'walkash'
require 'pp'

hash = {
  1 => { 2 => { 3 => { 4 => { 5 => { 6 => { 7 => {
    8 => { 9 => {10 => { 'fix' => 'wrong', 'ignore' => 'wrong' }}}}}}}}}}
}

fix_wrong = lambda do |working_hash, key, value|
  working_hash[key] = 'correct' if (key == 'fix') && (value == 'wrong')
end

pp hash
Walkash.walk(hash, [fix_wrong])
pp hash

kazu@utopia:~/dev/git/walkash$ ruby examples/walk_hash.rb

{1=>
  {2=>
    {3=>
      {4=>
        {5=>{6=>{7=>{8=>{9=>{10=>{"ignore"=>"wrong", "fix"=>"wrong"}}}}}}}}}}}
{1=>
  {2=>
    {3=>
      {4=>
        {5=>
          {6=>{7=>{8=>{9=>{10=>{"ignore"=>"wrong", "fix"=>"correct"}}}}}}}}}}}

Copyright © 2012 kazuyoshi tlacaelel. See LICENSE.txt for further details.

About

Walk a hash recursively with ease.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages