Can anybody shine some light on why this is behaving like this? I'm expecting the collection to omit nil results, and only collect those that qualify under the condition of the include?. First and third result entries, I expect to not be there. For some reason, they are indeed included. What am I doing wrong?
f = [
{"title"=>"Tuesday: Cloudy. High plus 12.",
"link"=>{"type"=>"text/html",
"href"=>"https://www.weather.gc.ca/city/pages/mb-42_metric_e.html"}},
{"title"=>"Tuesday night: Cloudy. High plus 2.",
"link"=>{"type"=>"text/html",
"href"=>"https://www.weather.gc.ca/city/pages/mb-42_metric_e.html"}},
{"title"=>"Wednesday: Cloudy. High plus 10.",
"link"=>{"type"=>"text/html",
"href"=>"https://www.weather.gc.ca/city/pages/mb-42_metric_e.html"}},
{"title"=>"Tuesday night: Cloudy. High plus 2.",
"link"=>{"type"=>"text/html",
"href"=>"https://www.weather.gc.ca/city/pages/mb-42_metric_e.html"}}
]
conditions = f.collect { |i| i['title'] if i['title'].include?('night') }
==> [nil, "Tuesday night: Cloudy. High plus 2.", nil, "Tuesday night: Cloudy. High plus 2."]