From: Chris Thiel Date: 2007-07-26T04:30:05+09:00 Subject: Re: Question - Passing parameters by reference ------=_Part_157291_6883550.1185391806411 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/25/07, Lionel Bouton wrote: > > Chris Thiel wrote the following on 25.07.2007 20:56 : > > I believe it's adding & in front of the argument in a method in C++ to > > get > > pass by reference. > > void add_one(&num) { > > num++ > > } > > > > Is there something that's equivalent in ruby? > > Ruby always pass references. The problem is that "number += 1" is > expanded as "number = number + 1". > > The problem here is that Fixnum#+ doesn't modify the object but > generates another one. So in fact it generates what happens is that a > new Object is created and then is referenced by number, but not by n. To > make it work like you want you would need to only use methods that > modify the object itself, which AFAIR don't exist in this context. > > Lionel. > > Yup, that's what I was wondering. Sorry to derail the thread a bit there. Chris ------=_Part_157291_6883550.1185391806411--