bikey77gy bikey77gy - 1 year ago 102
Ruby Question

Rails check if the value corresponding to a hash key is an empty array

A function in a rails 3 app returns the following hash


which I want to treat as a false result (meaning that if the hash value is an empty array I want to skip it).
How can I achieve the above?

Answer Source

Array#empty? and Hash#[] are the methods you need to look into.

h = {:"white-wines"=>[]}
puts "empty" if h[:"white-wines"].empty?
#= > empty
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download