Robert Dober wrote:
> Although I am a big fan with using #=== (for fingerlazyness) I have to
> agree, after some months of thinking and reading it is probably a bad
> idea to use it too much.

Sorry I came late to this party. I agree, and I can tell you why.
I'm using SimpleDelegate and mixins quite a bit, and I also have an
implementation of multiple inheritance (in my ActiveFacts project).

SimpleDelegate delegates the #class method, so d.class returns the
class of the thing it's delegating for... but === is defined in the
C code to use the internal class pointer; so === doesn't honour
the delegation:

class Bar; end
class Foo
def class; Bar; end
end
f=Foo.new
f.class    => Bar
Bar === f  => false

Furthermore, if I say "MyClass === thing", I'm asking MyClass to
determine whether "thing" is "people like us". There's no way you
can do anything in "thing" to spoof that - which is fundamentally
at odds with the principle of duck typing. If you want to quack like
a duck, I *shouldn't be able to tell* that you aren't.

On the other hand, "thing.is_a? MyClass" is a method on "thing", so
it gets to decide if it's the kind of thing you care about. This even
works when you define is_a? to give an affirmative response to multiple
unrelated classes; i.e. multiple inheritance:

class Bar; end
class Foo
def is_a? klass
super || klass == Bar
end
end
f=Foo.new       => #<Foo:0x74b6c>
f.is_a?(Foo)    => true
f.is_a?(Bar)    => true

This required me to convert almost all occurrences of === from my
code. If you want to say you're an Array, I'll believe you and talk
to you like an Array - it's not up to me to poke inside your C
definition and undermine your modified #class method, as === does.

I suspect this behaviour varies between Ruby variants too.

Clifford Heath.