# Very Basic Question

**URL:** <https://www.ruby-forum.com/t/very-basic-question/155064>\
**Category:** Ruby\
**Created:** [December 7, 2008, 8:56am UTC](https://www.ruby-forum.com/t/very-basic-question/155064 "2008-12-07T08:56:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilmangunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d07c76/32.png) [@gilmangunn](https://www.ruby-forum.com/u/gilmangunn)\
**Post date:** [December 7, 2008, 8:56am UTC](https://www.ruby-forum.com/t/very-basic-question/155064/1 "2008-12-07T08:56:04Z")

</div>

Hi all,

I have a very basic question… what does “=\>” mean? Two books I have  
looked at started using it without explaining and it is filtered in most  
searches.

My guess is that it has something to do with assignment but am not sure.

If anyone could shed some light on this it would be much appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![gilmangunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d07c76/32.png) [@gilmangunn](https://www.ruby-forum.com/u/gilmangunn)\
**Post date:** [December 7, 2008, 9:12am UTC](https://www.ruby-forum.com/t/very-basic-question/155064/2 "2008-12-07T09:12:52Z")

</div>

2008/12/7 Gilman G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I have a very basic question… what does “=\>” mean?

It’s how you assign values to keys in a hash.

letter\_values = { ‘a’ =\> 1, ‘b’ =\> 2, ‘c’ =\> 3,…, z =\> ‘26’ }  
letter\_values[‘b’] # 2  
letter\_values[‘j’] # 10

Farrel

---

<div class="post-metadata">

**Author:** ![gilmangunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d07c76/32.png) [@gilmangunn](https://www.ruby-forum.com/u/gilmangunn)\
**Post date:** [December 7, 2008, 9:57am UTC](https://www.ruby-forum.com/t/very-basic-question/155064/3 "2008-12-07T09:57:53Z")

</div>

On Sun, Dec 07, 2008 at 04:49:46PM +0900, Gilman G. wrote:

> Hi all,
> 
> I have a very basic question… what does “=\>” mean? Two books I have  
> looked at started using it without explaining and it is filtered in most  
> searches.
> 
> My guess is that it has something to do with assignment but am not sure.
> 
> If anyone could shed some light on this it would be much appreciated.

In addition to being used to assign values in hashes, it is also how the  
interactive Ruby interpreter (called “irb”) shows the return value for  
an  
expression. For instance, at my tcsh console one might see this:

```
~> irb
irb(main):001:0> foo = 'first'
=> "first"
irb(main):002:0> bar = 'second'
=> "second"
irb(main):003:0> print foo, ' and ', bar, "\n"
first and second
=> nil

```

These return value indicators are useful for figuring out exactly what a  
given expression does when writing code – you may have an editor open  
in  
which you are writing a program and, in another terminal emulator  
window,  
have irb running so you can check how various expressions are evaluated  
so you don’t have to guess or constantly search through documentation to  
be sure you’re using expressions correctly.

The `=>` in this usage is not actually part of the code, though the `=>`  
in hash assignments _is_ part of the code (of course).

I hope that helps. Other than those two uses of the `=>` character  
sequence, nothing springs immediately to mind.

---

<div class="post-metadata">

**Author:** ![gilmangunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d07c76/32.png) [@gilmangunn](https://www.ruby-forum.com/u/gilmangunn)\
**Post date:** [December 7, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/very-basic-question/155064/4 "2008-12-07T14:54:58Z")

</div>

Using =\> in method calls used to puzzle me. I encountered this for the  
first  
time in FXRuby, and then in Ruby on Rails.

It turned out that Ruby allows you to give a hash when invoking a  
method,  
where arguments to the method get rolled up into one hash variable.  
Consider  
this example (stolen from the Ruby P.ming Wikibook[0]):

def accept\_hash(var)  
print "got: ", var.inspect  
end  
accept\_hash :arg1 =\> ‘giving arg1’, :argN =\> ‘giving argN’

Hope you find this helpful.

Regards,  
Yaser S.

[0] [Ruby Programming - Wikibooks, open books for an open world](http://en.wikibooks.org/wiki/Ruby_Programming)

P.S. In the 1st edition of Programming Ruby, it is mentioned that  
keyword  
arguments “are scheduled to be implemented in Ruby 1.8”. Is this it  
(i.e.  
the keyword arguments feature), or is it something else?

---

<div class="post-metadata">

**Author:** ![gilmangunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d07c76/32.png) [@gilmangunn](https://www.ruby-forum.com/u/gilmangunn)\
**Post date:** [December 7, 2008, 3:26pm UTC](https://www.ruby-forum.com/t/very-basic-question/155064/5 "2008-12-07T15:26:38Z")

</div>

Yaser S. wrote:

> def accept\_hash(var)  
> print "got: ", var.inspect  
> end  
> accept\_hash :arg1 =\> ‘giving arg1’, :argN =\> ‘giving argN’

Better, Ruby 1.9 will let us fold the symbol and =\> notation:

arg1: ‘giving arg1’, argN: ‘giving argN’

This means that Ruby has invented the “named argument” system, but it  
did it the  
right way; by building the feature out of low-level syntax elements that  
we can  
reuse for other situations. Ruby did not do what some languages do -  
invent  
named arguments using their own magic system that only works in method  
argument  
lists.

---

<div class="post-metadata">

**Author:** ![gilmangunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d07c76/32.png) [@gilmangunn](https://www.ruby-forum.com/u/gilmangunn)\
**Post date:** [December 7, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/very-basic-question/155064/6 "2008-12-07T19:05:05Z")

</div>

Thx so much guys… I finally have my app up and running. No doubt more  
questions will follow!
