Ruby array search, returning either a result with a good score or the last result
You can always define your own custom method to refactor your code in the Array class:

class Array
  def find_or_last(&amp;block)
    find(&amp;block) || last 
  end
end


And use it like this:

array.select { |i| i['title'] == 'some title' }.find_or_last { |i| i['Zscore'].to_f &gt;= 5 }


You can also use procs or lambdas to achieve this.