From: Steve Litt Date: 2005-12-30T02:08:33+09:00 Subject: Re: What is the difference between :foo and "foo" ? On Thursday 29 December 2005 11:20 am, Kirk Haines wrote: > On Thursday 29 December 2005 8:45 am, Steve Litt wrote: > > They wouldn't exist, or they wouldn't be called symbols. If I'm referring > > to an instance instead of a value, I could call it &variable as in C, or > > I could call it :variable, but in that case I'd call it a reference, not > > a symbol. > > It's not a reference. Symbols are much simpler than that. Really. They > are just an integer with some sequence of characters to represent it, all > wrapped up in an object. OK, let me see if I'm correctly understanding you. :wilbur is an object. That object has two properties, which one could call, in generic and not Ruby terms, a key and a value. The key is an integer. The value is "wilbur". Neither the key nor the value can be changed during the execution of the program. When we write: attr_accessor :wilbur what really happens is that the function attr_accessor() takes symbol :wilbur as an argument, tacks on a @ to the string's value in order to make the true class variable @wilbur, and then writes a tiny get and set functions whose names are wilbur, such that: my_object.wilbur = 22 puts my_object.wilbur So my initial comment that it seemed like magic is true only to the extent that the "magic" performed by attr_accessor is to create the set and get methods with the same name as the symbol that is its argument. Do I understand what you're saying? Thanks SteveT Steve Litt http://www.troubleshooters.com slitt@troubleshooters.com