# What the hell is the =\> operator?

**URL:** <https://www.ruby-forum.com/t/what-the-hell-is-the-operator/119023>\
**Category:** Ruby\
**Created:** [November 2, 2007, 9:06am UTC](https://www.ruby-forum.com/t/what-the-hell-is-the-operator/119023 "2007-11-02T09:06:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [November 2, 2007, 9:06am UTC](https://www.ruby-forum.com/t/what-the-hell-is-the-operator/119023/1 "2007-11-02T09:06:13Z")

</div>

I’ve seen this in some ruby code but I have no idea what is going on.  
I’d do a google search on it but… I don’t search for ‘=\>’ and I don’t  
know  
how to describe it in english so that the context will be this!  
I’ve seen this operator used in, what seems to me, to be totally  
bizarre  
contexts. As far as I know, it’s only used in hash definitions.  
However,  
it’s used in both Rails and scRUBYt. It looks something like this:

method\_call :symbol =\> false do  
# do something here  
end

another\_method random\_var, :symbol =\> :other\_symbol do  
# do something else  
end

```
Can someone explain to me what is going on here?
Thank you...
```

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [November 2, 2007, 9:21am UTC](https://www.ruby-forum.com/t/what-the-hell-is-the-operator/119023/2 "2007-11-02T09:21:27Z")

</div>

Am Freitag, den 02. November 2007 um 09.06 Uhr schrieb Just Another  
Victim of the Ambient M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> end
> 
> another\_method random\_var, :symbol =\> :other\_symbol do
> 
> # do something else
> 
> end
> 
> Can someone explain to me what is going on here?

It’s mostly ‘syntactic sugar’. In Ruby you can leave the curly braces {}  
in a method call away in case the last values form a hash.

For example:

method\_call( param\_1, param\_2, :sym1 =\> ‘something’, ‘another\_key’ =\>  
:another\_value )

Note that you’re not limited to symbols as hash keys.

The following examples are esentially the same:

method\_call( :symbol =\> false ) do  
# do something here  
end

another\_method( random\_var, :symbol =\> :other\_symbol ) do  
# do something else  
end

method\_call( { :symbol =\> false } ) do  
# do something here  
end

another\_method( random\_var, { :symbol =\> :other\_symbol } ) do  
# do something else  
end

‘=\>’ is used to point from a hash key to its value.

Happy rubying

Stephan

---

<div class="post-metadata">

**Author:** ![maz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maz](https://www.ruby-forum.com/u/maz)\
**Post date:** [November 2, 2007, 10:06am UTC](https://www.ruby-forum.com/t/what-the-hell-is-the-operator/119023/3 "2007-11-02T10:06:26Z")

</div>

Just Another Victim of the Morality wrote:

> ```
> Can someone explain to me what is going on here?
> Thank you...
> 
> ```

def methA(arg)  
p arg  
end

methA({‘a’=\>10})  
methA(‘a’=\>10)  
methA ‘a’=\>10

–output:—  
{“a”=\>10}  
{“a”=\>10}  
{“a”=\>10}

def methB(arg)  
p arg  
end

methB({‘a’=\>10, ‘b’=\>20})  
methB(‘a’=\>10, ‘b’=\>20)  
methB ‘a’=\>10, ‘b’=\>20

–output:–  
{“a”=\>10, “b”=\>20}  
{“a”=\>10, “b”=\>20}  
{“a”=\>10, “b”=\>20}

def methC(arg1, arg2)  
p arg1, arg2  
end

methC(12.3, {‘a’=\>10, ‘b’=\>20})  
methC(12.3, ‘a’=\>10, ‘b’=\>20)  
methC 12.3, ‘a’=\>10, ‘b’=\>20

–output:—  
12.3  
{“a”=\>10, “b”=\>20}  
12.3  
{“a”=\>10, “b”=\>20}  
12.3  
{“a”=\>10, “b”=\>20}
