/ Published in: Ruby
URL: http://snippets.dzone.com/posts/show/1908
Check comments
Expand |
Embed | Plain Text
class Hash def extract_keys(keys = [], temp = []) temp = temp.dup temp2 = temp.dup self.each { |key, value| if value.class != Hash temp << key keys << temp #puts temp.inspect temp = [] end } temp = temp2 self.each { |key, value| if value.class == Hash temp << key keys = value.extract_keys(keys, temp) end } keys end end
You need to login to post a comment.
