From: Robert Dober Date: 2007-01-27T16:51:51+09:00 Subject: Re: pass by reference? ------=_Part_54984_14460306.1169884309134 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/27/07, dblack@wobblini.net wrote: > > Hi -- > > On Sat, 27 Jan 2007, Martin C. Martin wrote: > > > > > > > Phrogz wrote: > >> If you pass an immutable type by reference, does it make a sound? > >> Er, I mean... > >> If you passed an immutable type by reference, how would you know that > >> it wasn't passed by value? > > > > Is there any way for the function you're calling to modify the value of > the > > variable in the caller? Pass by reference can do that. > > You can modify the object to which the variable refers: > > def change_me(obj) > obj << "hi" > end > > arr = [1,2,3] > change_me(arr) > p arr # [1, 2, 3, "hi"] > > In this example, arr contains a reference to an array. In change_me, > obj contains another copy of the same reference, so you can use it to > manipulate and change the original array. > > I still wouldn't call this pass by reference (see my earlier post in > this thread). Just to demonstrate your point def modifying a_param a_param = "hi" end a_value = "low" modifying a_value case a_value when "hi" puts "Passed by reference" when "low" puts "Passed by value" else puts "Passed away" end or to put it different x = a.object_id method a a.object_id == x # for sure Robert David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.com) > > -- "The best way to predict the future is to invent it." - Alan Kay ------=_Part_54984_14460306.1169884309134--