Skip to content

Instantly share code, notes, and snippets.

@javier
Created December 7, 2009 17:13
Show Gist options
  • Save javier/250939 to your computer and use it in GitHub Desktop.
Save javier/250939 to your computer and use it in GitHub Desktop.
Hash.class_eval do
def deep_select(key)
res=[]
res << self[key]
values.select{|v| v.is_a?(Hash)}.each do |h|
children=h.deep_select(key)
res += children if children
end
res.compact!
res.empty? ? nil : res
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment