From: Brad Date: 2003-12-12T09:22:00+09:00 Subject: Re: Simple issue giving problems Gennady wrote: > > On Dec 11, 2003, at 14:37, Brad wrote: > > > Hello all, > > > > I have a problem that may or may not be an easy fix. :) > > > > Given the following: > > > > > > a=1 > > b=2 > > > > def swapper(dest,src) > > dest,src=src,dest > > end > > > If you put it this way: > > a=1 > b=2 > > dest=a > src=b > > dest,src=src,dest > > It swaps dest and src. And I do not think you would expect a and b > being swapped as well as a result of this. Same with calling a method > as in your example. You cannot deal with variables' addresses in Ruby > as in C. > True, in the case you present I would not expect a and b to be altered. But what I was wondering was if there were some way to allow manipulation of > > > > swapper(a,b) > > p [ a, b ] > > > > > > > > Why are the values of the variables not swapped? Is there > > a way to coerce ruby into doing a and b by using src and dest? > > > > Any help is greatly appreciated. > > > > Thanks, > > > > Brad > > > > > > Sincerely, > Gennady Bystritsky > > > >