Select makes sense. But can someone explain .detect to me? I don\'t understand these data.
>> [1,2,3,4,5,6,7].detect { |x| x.between?(3,4) }
=> 3
>&g
find
and detect
will always either return a single object or they will return nil
if nothing is matched:
[1,2,3,4,5,6,7].detect { |x| x.between?(1,7) }
=> 1
find_all
and select
will return an array of things that it finds that match:
[1,2,3,4,5,6,7].select { |x| x.between?(1,7) }
=> [1, 2, 3, 4, 5, 6, 7]
Reference Link