let\'s have this hash:
hash = {\"a\" => 1, \"b\" => {\"c\" => 3}} hash.get_all_keys => [\"a\", \"b\", \"c\"]
how can i get all key
This will give you an array of all the keys for any level of nesting.
def get_em(h) h.each_with_object([]) do |(k,v),keys| keys << k keys.concat(get_em(v)) if v.is_a? Hash end end hash = {"a" => 1, "b" => {"c" => {"d" => 3}}} get_em(hash) # => ["a", "b", "c", "d"]