Rails check if the value corresponding to a hash key is an empty array
16,575
Array#empty?
and Hash#[]
are the methods you need to look into.
h = {:"white-wines"=>[]}
puts "empty" if h[:"white-wines"].empty?
#= > empty
Related videos on Youtube
![bikey77gy](https://i.stack.imgur.com/hvLpt.png?s=256&g=1)
Comments
-
bikey77gy about 2 years
A function in a rails 3 app returns the following hash
{:"white-wines"=>[]}
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?