I’m using Rails 4.2.7. I want to find the first item in my array of objects whose fields match certain criteria. So I wrote this lengthy loop …
result = nil
results.each do |r|
result = r
Yup there is:
result = results.find(&:valid?)
Thanks to Rashmirathi for the ampersand + colon shortcut!