From: dblack@... Date: 2006-12-14T07:32:10+09:00 Subject: Re: Pointers and References? Hi -- On Thu, 14 Dec 2006, Eero Saynatkari wrote: > On 2006.12.14 05:20, dblack@wobblini.net wrote: >> Hi -- >> >> All of this means that if you do something to the arguments in a >> method, the changes are permanent in the original object: >> >> def add_element(array) >> array.push("new element!") >> end >> >> a = [1,2,3] >> add_element(a) >> p a > > Just to make it clearer: anything destructive or mutating you do to the > object inside the method will propagate to the original object. And yet clearer: the object inside the method IS the original object :-) >> Some values are immediate; i.e., when you assign a variable to them, >> they get stored directly and not via a reference: integers, true, >> false, nil, and symbols (and any I've forgotten). Hence the "almost >> everything" above. > > I think this can just be considered to be an implementation detail, > frankly. Fixnums etc. just do not have any destructive methods that > one could employ inside a method. The immediate-value thing does play a role in some language-design things, though, particularly the absence of x++ on the grounds that doing 1++ doesn't make any sense and, given x = 1, x *is* 1. David -- Q. What's a good holiday present for the serious Rails developer? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) aka The Ruby book for Rails developers! Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)