So I have a hash, and for each level of the hash, I want to store its key and value. The problem is, a value can be another hash array. Furthermore, that hash can contain ke
If you want to recursively edit the hash, you could do something like this:
# Iterates over a Hash recursively
def each_recursive(parent, &block)
parent.each do |path, value|
if value.kind_of? Hash
each_recursive parent, &block
elsif value.is_a? Array
# @TODo something different for Array?
else
yield(parent, path, container_or_field)
end
end
end
And you can do something like:
hash = {...}
each_recursive(hash) do |parent, path, value|
parent[path] = value.uppercase
end