From: macaco Date: 2008-02-06T02:37:13+09:00 Subject: Re: Having problems with my instance variable ------=_Part_13257_9365032.1202233039135 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks Day, but this is just a simplification of what I need @Andrew Stone, thanks instance_variable_set makes it's work, but what if i need the data inside too... for example def call_other(var1,var2) max = 8 if(var1 == 0) var1 = rand max else var1 += max end var2 = rand max end BTW, can you explain the line of code "c :@xpos", didn't get it Thanks again On Feb 4, 2008 11:03 PM, Andrew Stone wrote: > > def some > > call_other(@xpos,@ypos) > > end > > > > def more > > call_other(@other,@another) > > end > > > > This worked: > class Test > attr_reader :xpos > > def initialize > @xpos = 0 > end > > def some > p "before call: #{@xpos}" > #notice the colon > c :@xpos > p "after call: #{@xpos}" > end > > def call_other(var) > max = 9 > self.instance_variable_set(var, rand(max)) > end > end > > begin > t = Test.new > t.some > end > > wyz@local ~ $ ruby test.rb > "before call: 0" > "after call: 7" > > wyz@local ~ $ ruby test.rb > "before call: 0" > "after call: 2" > > Warning: I'm not feeling well and the NyQuil is kicking in... :/ > > -- > Andrew Stone > ------=_Part_13257_9365032.1202233039135--