From: Kirk Haines Date: 2005-12-31T05:29:23+09:00 Subject: Re: What is the difference between :foo and "foo" ? On Friday 30 December 2005 1:03 pm, Austin Ziegler wrote: > Please edit your guide, as it is *not* correct when it says: > > A Ruby symbol is a thing that has both a number (integer) and a string. > > This is not correct in any way. If you leave it as "A Ruby Symbol is a > thing", you're fine. But when you say that it "has" a number and a > string, you are incorrect. Symbols are not composed of the integer or > string values that you can convert Symbols to; they just are. The > value of a Symbol is not its String value or its Fixnum value, but > itself. I think that I am probably the source for this confusion, and I am guilty of not clarifying further what I meant. :foo is a symbol. The string representation of :foo is 'foo'. :foo.to_s :foo also has an integer that id, found with #object_id: :foo.object_id This is no different than any other object. What is different is this: irb(main):001:0> 'foo'.object_id => -609482574 irb(main):002:0> 'foo'.object_id => -609486184 irb(main):003:0> 'foo'.object_id => -609489724 The id changes because each 'foo' is a different object. irb(main):004:0> :foo.object_id => 3957006 irb(main):005:0> :foo.object_id => 3957006 irb(main):006:0> :foo.object_id => 3957006 The id doesn't change because :foo is just :foo -- it's the same object every time. Kirk Haines