Skip to content

Instantly share code, notes, and snippets.

@abigezunt
Created November 27, 2013 14:55
Show Gist options
  • Save abigezunt/7677027 to your computer and use it in GitHub Desktop.
Save abigezunt/7677027 to your computer and use it in GitHub Desktop.
def values(hsh, key)
return [] if !hsh.kind_of? Hash
v = hsh[key] ? [hsh[key]] : []
hsh.values.select{|i| i.kind_of? Hash or i.kind_of? Array}.each do |val|
if val.kind_of? Hash
v+= values(val, key)
else
val.each {|i| v+= values(i, key)}
end
end
return v
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment