First element of an array with condition

arrays, ruby

Solution

Try this:

my_array.find{|x| x.some_test }

Or here's a shortcut (thanks @LarsHaugseth for reminding about it)

my_array.find(&:some_test)

Problem

Is there a shorter way to find the first element in an array meeting some conditions than this: ``` my_array[ my_array.index {|x| x.some_test} ] ```

Original source