Top Level Namespace
Defined Under Namespace
Modules: KhanAcademy, Rubykhan
Instance Method Summary collapse
Instance Method Details
#values(hsh, key) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rubykhan.rb', line 5 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 |