# Ruby 1.9 named arguments

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351>\
**Category:** Ruby\
**Created:** [March 30, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351 "2008-03-30T20:20:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 30, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351/1 "2008-03-30T20:20:40Z")

</div>

When I run the following in the irb session, I am getting an error.  
Any ideas why? TIA.  
irb(main):036:0\> { :a =\> 1, :b =\> 4 }  
=\> {:a=\>1, :b=\>4}  
irb(main):037:0\> { :x 2, :y 6 }  
SyntaxError: (irb):37: syntax error, unexpected tINTEGER, expecting  
tASSOC  
{ :x 2, :y 6 }  
^  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/workspace.rb:81:in  
`eval' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/workspace.rb:81:in`evaluate’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/context.rb:219:in  
`evaluate' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:150:in`block (2  
levels) in eval\_input’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:259:in  
`signal_status' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:147:in`block in  
eval\_input’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/ruby-lex.rb:244:in  
`block (2 levels) in each_top_level_statement' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/ruby-lex.rb:231:in`loop’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/ruby-lex.rb:231:in  
`block in each_top_level_statement' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/ruby-lex.rb:230:in`catch’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb/ruby-lex.rb:230:in  
`each_top_level_statement' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:146:in`eval\_input’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:70:in `block in start' from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:69:in`catch’  
from /Users/bparanj/ruby19/lib/ruby/1.9.0/irb.rb:69:in `start' from /Users/bparanj/ruby19/bin/irb:13:in`’  
Maybe IRB bug!!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 30, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351/2 "2008-03-30T20:25:26Z")

</div>

Hi –

On Mon, 31 Mar 2008, removed\_email\_address@domain.invalid wrote:

> When I run the following in the irb session, I am getting an error.  
> Any ideas why? TIA.  
> irb(main):036:0\> { :a =\> 1, :b =\> 4 }  
> =\> {:a=\>1, :b=\>4}  
> irb(main):037:0\> { :x 2, :y 6 }  
> SyntaxError: (irb):37: syntax error, unexpected tINTEGER, expecting  
> tASSOC  
> { :x 2, :y 6 }  
> ^

You mean:

{ x: 2, y: 6 }

David

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 30, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351/3 "2008-03-30T20:26:40Z")

</div>

removed\_email\_address@domain.invalid wrote:

> When I run the following in the irb session, I am getting an error.  
> Any ideas why? TIA.  
> irb(main):036:0\> { :a =\> 1, :b =\> 4 }  
> =\> {:a=\>1, :b=\>4}  
> irb(main):037:0\> { :x 2, :y 6 }  
> SyntaxError: (irb):37: syntax error, unexpected tINTEGER, expecting  
> tASSOC  
> { :x 2, :y 6 }  
> ^

I think you’re confusing symbol hash keys with 1.9’s named arguments:

foo(:a =\> 1, :b =\> 2) # symbol hash keys  
foo(a:1, b:2) # 1.9 named arguments

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 30, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351/4 "2008-03-30T20:34:59Z")

</div>

Hi –

On Mon, 31 Mar 2008, Tim H. wrote:

> I think you’re confusing symbol hash keys with 1.9’s named arguments:
> 
> foo(:a =\> 1, :b =\> 2) # symbol hash keys  
> foo(a:1, b:2) # 1.9 named arguments

They’re still symbols in a hash, though. Just the notation is  
different:

irb(main):004:0\> def x(a); p a; end  
=\> nil  
irb(main):005:0\> x(x: 1, y: 2)  
{:x=\>1, :y=\>2}

David

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 30, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351/5 "2008-03-30T20:29:41Z")

</div>

On Sun, Mar 30, 2008 at 2:20 PM, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> When I run the following in the irb session, I am getting an error.  
> Any ideas why? TIA.  
> irb(main):036:0\> { :a =\> 1, :b =\> 4 }  
> =\> {:a=\>1, :b=\>4}  
> irb(main):037:0\> { :x 2, :y 6 }  
> SyntaxError: (irb):37: syntax error, unexpected tINTEGER, expecting  
> tASSOC  
> { :x 2, :y 6 }  
> ^

Is this what you were trying to do?

$ irb1.9  
irb(main):001:0\> {x: 2, y: 6}  
=\> {:x=\>2, :y=\>6}

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 30, 2008, 9:24pm UTC](https://www.ruby-forum.com/t/ruby-1-9-named-arguments/133351/6 "2008-03-30T21:24:58Z")

</div>

David A. Black wrote:

> They’re still symbols in a hash, though. Just the notation is  
> different:

I see. Thanks for explaining.
