# Operator =\>

**URL:** <https://www.ruby-forum.com/t/operator/105377>\
**Category:** Ruby\
**Created:** [May 29, 2007, 1:33pm UTC](https://www.ruby-forum.com/t/operator/105377 "2007-05-29T13:33:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [May 29, 2007, 1:33pm UTC](https://www.ruby-forum.com/t/operator/105377/1 "2007-05-29T13:33:40Z")

</div>

Hi I have a beginner question

What does the =\> operator do?

here is the example code from the book

class Product \< ActiveRecord::Base  
has\_many :orders, :through _=\>_ :line\_items  
#…

---

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [May 29, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/operator/105377/2 "2007-05-29T13:45:44Z")

</div>

Alle martedì 29 maggio 2007, Gian H. ha scritto:

> Hi I have a beginner question
> 
> What does the =\> operator do?
> 
> here is the example code from the book
> 
> class Product \< ActiveRecord::Base  
> has\_many :orders, :through _=\>_ :line\_items  
> #…

=\> is not an operator, its simply the syntax used to create hashes:

h = {:a =\> 1, :b=\>2}

creates an hash with keys :a and :b, corresponding to values 1 and 2  
respectively. When you need to pass an hash as the last argument of a  
method,  
ruby allows you to omit the braces, so your call to has many means:

has\_many( :orders, {:through =\> :line\_items} )

In other words, you’re passing two arguments to the method has\_many: the  
first  
is the Symbol :orders; the second is a Hash with one key (:through) and  
one  
value (:line\_items)

Stefano

---

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [May 30, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/operator/105377/3 "2007-05-30T19:58:08Z")

</div>

Thanks so much

---

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [May 31, 2007, 10:25am UTC](https://www.ruby-forum.com/t/operator/105377/4 "2007-05-31T10:25:32Z")

</div>

On Thu, May 31, 2007 at 02:57:19AM +0900, Gian H. wrote :

> > =\> is not an operator, its simply the syntax used to create hashes:
> > 
> > h = {:a =\> 1, :b=\>2}

Looking at the trunk, my understanding is that it will be replaced by :  
in a next release? Correct?

---

<div class="post-metadata">

**Author:** ![glacius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dec6dc/32.png) [@glacius](https://www.ruby-forum.com/u/glacius)\
**Post date:** [June 1, 2007, 3:37am UTC](https://www.ruby-forum.com/t/operator/105377/5 "2007-06-01T03:37:38Z")

</div>

Hi,

At Thu, 31 May 2007 17:24:42 +0900,  
Pierre-Alexandre M. wrote in [ruby-talk:253715]:

> > > h = {:a =\> 1, :b=\>2}
> 
> Looking at the trunk, my understanding is that it will be replaced by :  
> in a next release? Correct?

It’s a syntax sugar but traditional syntax is still valid. The  
above example is equivalent to:

h = {a: 1, b: 2}
