------art_156267_14822382.1185386382236
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 7/25/07, Todd Benson <caduceass / gmail.com> wrote:
>
> On 7/25/07, caof2005 <caof2005 / 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  ;
> >      val  val * 10) / cad.to_i
> >      temp  ad.to_i + 3.to_i
> >      cad  emp.to_s
> > end
> > ....
> > ....
> > val  5;
> > 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  5, "7"
> x, y  ( x, y ) #this will make x equal to 50 and y equal to the string
> "10"
>
> Does that make sense?
>
> Todd
>
> What if the method is returning something else already and you don't want
to have to return the changed value? How do you pass in a variable to a
method and have the change stick when it exists the method in ruby?
Chris

------art_156267_14822382.1185386382236--