let\'s have this hash:
hash = {\"a\" => 1, \"b\" => {\"c\" => 3}} hash.get_all_keys => [\"a\", \"b\", \"c\"]
how can i get all key
I find grep useful here:
grep
def get_keys(hash) ( hash.keys + hash.values.grep(Hash){|sub_hash| get_keys(sub_hash) } ).flatten end p get_keys my_nested_hash #=> ["a", "b", "c"]
I like the solution as it is short, yet it reads very nicely.