I have a nested hash like this:
s = Struct.new :topic_version
s_blank = s.new
s_bar = s.new "bar"
s_foo = s.new "foo"
h = {
:aa=>{:services=>[nil, s_blank, s_bar]},
:ab=>{:services=>[s_blank, nil, s_bar, s_bar]},
:ac=>{:services=>[nil, s_foo, s_blank]}
}
And I'd like to get an array of string values eg. ["bar", baz"]
My attempt is:
@topic_version_collection = []
h.each do |key, value|
value[:services].each do |v|
@topic_version_collection << v.topic_version
end
end
And it works if there aren't any nil values in the array.
But how can I make it work with nils?
"baz"come from? Can you add anif !v.nil?check?S = Struct.new :topic_version