Skip to content

Instantly share code, notes, and snippets.

@slowernet
Created June 11, 2015 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slowernet/b41289f67dfd972027f9 to your computer and use it in GitHub Desktop.
Save slowernet/b41289f67dfd972027f9 to your computer and use it in GitHub Desktop.
traverse a nested hash, yielding keypath and value
class Hash
# traverse a nested hash, yielding keypath and value
def walk(path = [], &block)
self.each do |k,v|
path.push(k)
v.is_a?(Hash) ? v.walk(path, &block) : yield(path, v)
path.pop
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment