From: Tim Pease Date: 2006-07-25T01:07:19+09:00 Subject: Re: Dumb question about assigments Ruby only allows a single value to be assigned using the = operator. However, you can assign an array to multiple values: a, b = [1, 2] puts a #=> 1 puts b #=> 2 When you try to assign multiple values using the = operator you defined, Ruby is converting the arguments on the right hand side into an array; hence the "1 for 2" argument error you mentioned. I would try something like this class BlahBlah def something=( *args ) x, y = args puts x puts y end end BlahBlah.new.something = 1 BlahBlah.new.something = 1, 2 #=> 1 #=> nil #=> 1 #=> 2 In the first assignment, y gets the value of nil. Hope this helps :) TwP On 7/24/06, Andrew Huh? wrote: > Hi, I feel kind of dumb for asking this, but I can't honestly find the > answer anywere. > > I came across a attribute defined like: > class BlahBlah > def something=(x,y) > #code > end > end > > I tried to assign the values as: > BlahBlah.something=(5,10) > and > BlahBlah.something=5,10 > and > BlahBlah.something(5,10) > > but all give me a "1 for 2" argument error (except for the last which > don't work because something is not a method). > All examples I came across either used only one argument, or defined > something as a method (strip the =). > > How can I assign values to this tipe of attribute? > thanks > > -- > Posted via http://www.ruby-forum.com/. > >