Hi -- On Fri, 30 Dec 2005, Steve Litt wrote: > On Thursday 29 December 2005 10:16 am, dblack / wobblini.net wrote: >> >> Just out of curiosity: can you describe how symbols would work if >> they weren't surprising? > > 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. But it's not a reference; it's an object, of class Symbol. If you do: s = :sym then the variable s holds a reference to the object :sym, just as when you do: a = [] a holds a reference to that array. > Personally, I think of the referencing and dereferencing in C as being > unsurprising. C has plenty of surprises, but referencing and dereferencing is > not one. Referencing and related things are so completely different as between Ruby and C, though. They really don't map onto each other at all. >> From what I understand, symbols are used for things other than naming > objects/variables. In such cases, it would be less surprising if they had a > different syntax than the ones that name objects. They do; they have a literal constructor (:sym). That's always a symbol first and foremost; and if there happens to be a method called "sym", there may be some contexts in which you can use a symbol to refer to it, but that's only because something is implemented to do that (such as: obj.method(:sym)). I think one important key to understanding symbol objects is their immediacy. When you see :sym, it's very similar to seeing an integer. It *is* the object. What gets done with the object, or what methods do or do not know how to use it to pry out methods or other things, is secondary. David -- David A. Black dblack / wobblini.net "Ruby for Rails", from Manning Publications, coming April 2006! http://www.manning.com/books/black