On Jul 25, 10:54 am, "Todd Benson" <caduce... / gmail.com> wrote: > On 7/25/07, caof2005 <caof2... / gmail.com> wrote: > > > > > Hello Folks > > > My question is the following: > > > How can I pass a reference to a method as an argument, so after > > finishing the execution of the method the argument gets updated with a > > new value. ( known as "pass by reference" in other languages ). > > > example: > > .... > > def changeValue( val, cad ) > > temp = 0; > > val = (val * 10) / cad.to_i > > temp = cad.to_i + 3.to_i > > cad = temp.to_s > > end > > .... > > .... > > val = 35; > > cad = "7" > > > puts "val before calling changeValue:= " + val.to_s > > puts "cad before calling changeValue:=" + cad > > > changeValue( val, cad ) > > > puts "val before calling changeValue:= " + val.to_s #--- I pretend > > to print '50' > > puts "cad before calling changeValue:=" + cad #--- I pretend > > to print '10' > > > Regards > > Carlos > > Assignment inside method scope is allowed, but creates a different > object. What you get back from a method is what the method returns. > So you could mimic your desired behavior with... > > def f(a, b) > return a*10.0/b.to_i, (b.to_i+3).to_s > end > > x, y = 35, "7" > x, y = f( x, y ) #this will make x equal to 50 and y equal to the string "10" > > Does that make sense? > > Todd Todd: Although it did not change neither of both parameters and I suppose you can't do this in Ruby, at the end you showed me a new technique that can mimic the behavior. Thanks so much for this tip!!! Carlos