I often use .group_by{ |x| x }and.find{ |x| x }
The latter should find the first element in the array, which is true.
Currently I just use it .compact.first, but I feel that there should be an elegant way to use it here, for example, find(&:to_bool)or .find(true)that I am missing.
Usage .find(&:nil?)works, but the opposite of what I want, and I could not find a method opposite #find or #detect, or a method like #true?
So, is there a more elegant way to write .find{ |x| x }? If not, I will stick .compact.first
(I know that compact will not remove false, but that is not a problem for me, also please avoid rails methods for this)
Edit: for my exact case, it is used on arrays of only strings and niles, for example
[nil, "x", nil, nil, nil, nil, "y", nil, nil, nil, nil]=>"x"
source
share