let's have this hash:
hash = {"a" => 1, "b" => {"c" => 3}}
hash.get_all_keys
=> ["a", "b", "c"]
how can i get all keys since hash.keys
returns just ["a", "b"]
let's have this hash:
hash = {"a" => 1, "b" => {"c" => 3}}
hash.get_all_keys
=> ["a", "b", "c"]
how can i get all keys since hash.keys
returns just ["a", "b"]
hash.keys
is the simplest one I have seen to return an array of the key values in a hash.Version that keeps the hierarchy of the keys
keys_only.rb
P.S.: Yes, it looks like a lexer :D
Bonus: Print the keys in a nice nested list
Also deal with nested arrays that include hashes
I find
grep
useful here:I like the solution as it is short, yet it reads very nicely.
This will give you an array of all the keys for any level of nesting.