[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about the threequal operator .===

jweizman

8/15/2006 8:15:00 AM

Hi

I'm a newbie on ruby and i have some questions :
*What is special to the threequals operator when it comes to when
clause ?
object === other_object

*What is the "." in front of the operator ?
object .=== other_object
Thanks
John

2 Answers

Robert Klemme

8/15/2006 8:27:00 AM

0

On 15.08.2006 10:15, John wrote:
> Hi
>
> I'm a newbie on ruby and i have some questions :
> *What is special to the threequals operator when it comes to when
> clause ?
> object === other_object

It's simply the fact that it's invoked. "when" doesn't invoke ==, eql?
or equal? but ===.

> *What is the "." in front of the operator ?
> object .=== other_object

This is just the normal method invocation syntax. Note that an operator
in Ruby is nothing else than an instance method with a special
invocation syntax.

>> 10:25:00 [~]: irbs
>> o = Object.new
=> #<Object:0x3f2ac8>
>> def o.===(x) p x end
=> nil
>> o === 1
1
=> nil
>> o.=== 1
1
=> nil
>> o.===(1)
1
=> nil
>> o.send :===, 1
1
=> nil

These are all equivalent pieces of code.

Kind regards

robert

Austin Ziegler

8/15/2006 2:47:00 PM

0

On 8/15/06, Robert Klemme <shortcutter@googlemail.com> wrote:
> On 15.08.2006 10:15, John wrote:
> > Hi
> >
> > I'm a newbie on ruby and i have some questions :
> > *What is special to the threequals operator when it comes to when
> > clause ?
> > object === other_object
>
> It's simply the fact that it's invoked. "when" doesn't invoke ==, eql?
> or equal? but ===.

And it does it differently than might be expected.

case object
when other_object
end

is the same as other_object === object, not the other way around.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca