let\'s have this hash:
hash = {\"a\" => 1, \"b\" => {\"c\" => 3}} hash.get_all_keys => [\"a\", \"b\", \"c\"]
how can i get all key
Here is another approach :
def get_all_keys(h) h.each_with_object([]){|(k,v),a| v.is_a?(Hash) ? a.push(k,*get_all_keys(v)) : a << k } end hash = {"a" => 1, "b" => {"c" => {"d" => 3}}} p get_all_keys(hash) # >> ["a", "b", "c", "d"]