From: "David A. Black" Date: 2008-07-14T08:40:21+09:00 Subject: Re: Passing arguments to a class, how do? --1926193751-80049348-1215992687=:28676 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-80049348-1215992687=:28676" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-80049348-1215992687=:28676 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Mon, 14 Jul 2008, I=C3=B1aki Baz Castillo wrote: > El Domingo, 13 de Julio de 2008, Luiz Vitor Martinez Cardoso escribi=C3= =B3: >> I'm learning Ruby, and i need to solve a problem: >> >> >> class Person >> def namer=3D(name, surname) >> @var =3D name >> @car =3D surname >> end >> end >> >> object =3D Person.new >> object.namer =3D (how to pass the params here) ? > > I don't know why but it's not possible to define an instance method sufix= ed > with "=3D" and requiring more than one parameter, it gives an error when > passing parameters: > > irb> object.namer=3D("NAME","SURNAME") > SyntaxError: compile error > (irb):34: syntax error, unexpected ',', expecting ')' The idea of the =3D-methods is that they use assignment syntax, and you can't do this: x=3D(1,2) > But you can use "send": > > irb> object.send("namer=3D","NAME","SURNAME") That kind of eliminates the nice assignment syntax :-) Try this: def namer=3D(args) p args end object.namer =3D "David", "Black" # =3D> ["David", "Black"] David --=20 Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ Advancing With Rails August 18-21 Edison, NJ See http://www.rubypal.com for details and updates! --1926193751-80049348-1215992687=:28676-- --1926193751-80049348-1215992687=:28676--