ruby - Iterating through nested hashes named using strings -
i'm having trouble iterating through series of nested hashes, , think because inner hashes named strings. unfortunately, cannot change these names. here generic hash of kind working with:
hash = "name" => { "stuff" => "value", "key" => "value", }, "name" => { "stuff" => "value", "key" => "value", },
i'm trying write program print fields labelled "name" values, within, when called names of keys. right now, stuck
hash.each |key, value| puts key key.each |stuff, info| puts info if category == "stuff" end end
but gives error each not recognized method key, is, think, because computer treating string due naming. have ideas how can proceed here (without changing names of keys)?
as @meager says - sub-hash in value. try this
hash.each |key, sub_hash| puts key sub_hash.each |category, info| puts info if category == "stuff" end end
Comments
Post a Comment