# Question about the threequal operator .===

**URL:** <https://www.ruby-forum.com/t/question-about-the-threequal-operator/64962>\
**Category:** Ruby\
**Created:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/question-about-the-threequal-operator/64962 "2006-08-15T14:20:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/question-about-the-threequal-operator/64962/1 "2006-08-15T14:20:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [August 15, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/question-about-the-threequal-operator/64962/2 "2006-08-15T14:21:00Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [August 15, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/question-about-the-threequal-operator/64962/3 "2006-08-15T16:47:43Z")

</div>

On 8/15/06, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
