PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Ruby 1.9 named arguments
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Ruby 1.9 named arguments

Réponse
 
LinkBack Outils de la discussion
Vieux 30/03/2008, 19h17   #1
bparanj@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Ruby 1.9 named arguments

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 `<main>'
Maybe IRB bug!!
  Réponse avec citation
Vieux 30/03/2008, 19h23   #2
David A. Black
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Ruby 1.9 named arguments

Hi --

On Mon, 31 Mar 2008, bparanj@gmail.com 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

--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS April 14-17 New York City
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
See http://www.rubypal.com for details and updates!

  Réponse avec citation
Vieux 30/03/2008, 19h24   #3
Tim Hunter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Ruby 1.9 named arguments

bparanj@gmail.com 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


--
RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

  Réponse avec citation
Vieux 30/03/2008, 19h28   #4
Rick DeNatale
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Ruby 1.9 named arguments

On Sun, Mar 30, 2008 at 2:20 PM, bparanj@gmail.com <bparanj@gmail.com> 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/

  Réponse avec citation
Vieux 30/03/2008, 19h34   #5
David A. Black
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Ruby 1.9 named arguments

Hi --

On Mon, 31 Mar 2008, Tim Hunter wrote:

> bparanj@gmail.com 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


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

--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS April 14-17 New York City
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
See http://www.rubypal.com for details and updates!

  Réponse avec citation
Vieux 30/03/2008, 20h24   #6
Tim Hunter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Ruby 1.9 named arguments

David A. Black wrote:
>
> They're still symbols in a hash, though. Just the notation is
> different:
>


I see. Thanks for explaining.

--
RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h50.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10939 seconds with 14 queries