From: "David A. Black" Date: 2009-11-01T02:08:00+09:00 Subject: Re: In-place parameter modification Hi -- On Sun, 1 Nov 2009, Dave Anderson wrote: > 7stud -- wrote: >> Judson Lester wrote: >>> Finally: ruby is a pass-by-reference language, so if you actually do >>> make >>> changes the parameters of a method, the callers variables will change as >>> well. >> >> def test(x) >> x = 10 >> end >> >> num = 5 >> test num >> puts num >> >> --output:-- >> 5 >> >> ??? > > My educated guess is that string.replace("Chunky bacon") is operating on > the original, whereas string = "Chunky bacon" just makes a new local > copy. The pickaxe book suggests that this only works on Arrays, Hashes > and Strings, though, so there's no way to make replace work on a fixnum. That's a good thing :-) David -- The Ruby training with D. Black, G. Brown, J.McAnally Compleat Jan 22-23, 2010, Tampa, FL Rubyist http://www.thecompleatrubyist.com David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)