On Mon, Aug 23, 2010 at 8:52 AM, Ralph Shnelvar <ralphs / dos32.com> wrote:

> irb(main):001:0> class X
> irb(main):002:1> end
> =3D> nil
> irb(main):003:0> x =3D X.new
> =3D> #<X:0x4d3a660>
> irb(main):004:0> x =3D=3D=3D X
> =3D> false   # this is surprising
> irb(main):005:0> X =3D=3D=3D x
> =3D> true    # this is the test I want ... but was surprised when
>           # x =3D=3D=3D X didn't work.
> irb(main):006:0>
> - - - - -
>
> Does x =3D=3D=3D X ever mean anything useful?


Typically, you define X#=3D=3D=3D to be whatever is meaningful for you. So =
the
answer depends on how you define it. Typically, when considering how you
want to define it, you should be thinking about how you want it used in a
case statement. For example, classes typically are used in a case statement
to check if an object is an instance of that class:

X =3D Class.new
x =3D X.new
case x
when String
  puts "Do stringy thing"
when Regexp
  puts "Do regexy thing"
when X
  puts "Do Xy thing"
else
  puts "Don't know what to do"
end

Is the same as

X =3D Class.new
x =3D X.new
if String =3D=3D=3D x
  puts "Do stringy thing"
elsif Regexp =3D=3D=3D x
  puts "Do regexy thing"
elsif X =3D=3D=3D x
  puts "Do Xy thing"
else
  puts "Don't know what to do"
end


In your example, note that the reason X =3D=3D=3D x in this case works, is =
because
X inherits its =3D=3D=3D method from Module where "Case Equality=97Returns =
true if
anObject is an instance of mod or one of mod=91s descendents. Of limited us=
e
for modules, but can be used in case statements to classify objects by
class." http://ruby-doc.org/core/classes/Module.html#M001666


If you want to think of it as an operator, think of it like the minus sign,
where 2-1 is not equal to 1-2, but probably the best thing would be to not
think of it as an operator, but rather as a method exclusively intended for
the convenience of case statements. Notice that the docs even preceed the
description with "Case Equality".