From: dblack@... Date: 2006-01-05T08:13:13+09:00 Subject: Re: On Symbols Hi -- On Thu, 5 Jan 2006, Dave Howell wrote: > dblack said: >> a = "string" # a contains a reference to that string >> a = 1 # a contains the actual (immediate) value 1 > > Except the example would seem to contradict this statement. `a' `b' and `c' > do not contain actual anythings. They contain references to the same object, > that object which is the value "1". > > Maybe. I guess it depends on what, exactly, the .object_id method returns, or > on what "actual" or "immediate" means. It would appear it means something > much less immediate than I'd expect. I've always conceptualized it as pretty much a value vs. pointer difference. I avoid the word "pointer" because (a) Matz never calls it that, and (b) it's not a matter of physical memory, but a Ruby-side notion of reference. Still, it's close to the same idea. Fixnums, Symbols, true, false, and nil get assigned directly to variables. For other objects, variables get a reference to the object. References, like variables, are not themselves objects. They're part of a kind of language substratum on which the object system floats. I think that's all there is to it. In fact, in a sense there's even less to it, since Ruby handles any necessary de-referencing for you, so you don't have to make any explicit distinction in your code. > Once again, a gentle reminder: please feel free to comment on the learning > process I'm documenting if you like, but do NOT respond if you're going to > try to explain more about symbols and whatnot. Thanks! I'm giving myself a directly-quoted-person exemption :-) David -- David A. Black dblack@wobblini.net "Ruby for Rails", from Manning Publications, coming April 2006! http://www.manning.com/books/black