On Jan 3, 11:58  𮮮wrote:
> But yeah, I don't usually explicitly use === either.

I would say that === 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
===.

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 === el } ; end  ;nd
array = ['foo','bar',2,'7','hi' ]
array.grep_first Numeric # => 2
array.grep_first /\d/ # => '7'
array.grep_first 'bar' # => 'bar'
array.grep_first 'foobar' # => 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