From: Todd Benson Date: 2007-07-26T02:54:17+09:00 Subject: Re: Question - Passing parameters by reference On 7/25/07, caof2005 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