On Jan 3, 11:58=A0pm, Sebastian Hungerecker <sep... / googlemail.com>
wrote:
> But yeah, I don't usually explicitly use =3D=3D=3D either.

I would say that =3D=3D=3D is more appropriate in the case where you are
generalizing and the thing you might match against will vary. This is
in fact what grep does - it will work on anything that responds to
=3D=3D=3D.

For example, it would be useful in the case of a find version of grep
(to solve the above problem with grep iterating over the whole array).
Let's call it grep_first:

class Array ; def grep_first pat ; find { | el | pat =3D=3D=3D el } ; end  ;=

end
array =3D ['foo','bar',2,'7','hi' ]
array.grep_first Numeric # =3D> 2
array.grep_first /\d/ # =3D> '7'
array.grep_first 'bar' # =3D> 'bar'
array.grep_first 'foobar' # =3D> nil

But if you specifically _know_ you are matching a type then I think
is_a or kind_of is probably better. Interested in others' take on
this.

Regards,
Dan

---
Dan Yoder
dev.zeraweb.com