From: dblack@... Date: 2007-08-08T06:18:38+09:00 Subject: Re: Question - Passing parameters by reference Hi -- On Wed, 8 Aug 2007, Gary Wright wrote: > > On Aug 6, 2007, at 8:16 PM, Logan Capaldo wrote: > >> this seemed to illustrate it better in my head. Seeing it typed out, it >> doesn't look so insightful. I guess what I'm trying to say is. don't think >> of literals as ways of referring to objects, think of them as method calls >> that return objects. Or something like that. >> > > > It is confusing to me to even think about methods returning objects unless > you are using that as a very specific shorthand for saying that methods > return *references* to objects. That is the unifying idea that helped me > understand how Ruby manipulates data--it is all references and not the > objects themselves. The objects themselves are almost completely hidden > from the programmer (excluding C extensions) in Ruby. Everything is a > reference to an object. At least that is the way I have come to understand > things but it means that you have to ditch the idea that Fixnum's and > Symbols (and true, false, nil) are somehow special cases. In my mind they > are not. The literals :blue, 42, true, false, nil are all references to > particular objects and assignment is the process of binding a reference to > a variable. You're using the term "reference" in two different ways, though: first, as a synonym for a literal constructor (the actual "ink on the page", so to speak), and second as the thing bound to an object. But consider something like: a = "blue".to_sym or x = 10 + 10 The literals :blue and 20 never occur, but a and x are in exactly the same state they'd be in if I'd done: a = :blue x = 20 So my variables must be bound to something other than a reference, if "reference" means the those literals. I guess I'd say that: :blue "blue".to_sym 10 + 10 20 etc. are expressions (rather than references), and that every expression evaluates to an object. Then there's the question of what happens with assignment. I'm not sure how "canonical" the notion of the universal reference is (not just as a matter of implementation) -- but it probably doesn't matter too much either way as long as (im)mutability and uniqueness, which are really object properties, are clear. My only concern is cases where the fact that something is an immediate value might explain some behavior that might otherwise seem unclear or pointless (like the ++ operator case). David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)