From: Austin Ziegler Date: 2005-12-31T00:55:55+09:00 Subject: Re: What is the difference between :foo and "foo" ? On 30/12/05, Steve Litt wrote: > Long time Rubyists, people with heavy CS studies, and people who have > experience in languages with symbols (LISP, I guess) tend to talk more > about how it's implemented, while programmers (probably without CS > degrees) migrating from languages not containing symbols are more > interested in what it does than how it's implemented. And what I've been trying to get across, Steve, is that Symbols don't actually *do* anything. Nothing. Zero. Zip. ABSOLUTELY NADA! They're names with the special property that the name uniquely identifies the object. :wilbur always identifies :wilbur. > I asked if it's an object with 2 attributes, an integer key and a > string value. Someone says no, it's an object with one attribute that > can be seen 2 ways, a string or an integer. From my point of view, > he's saying the same thing. Then you didn't understand the answer if you saw them as the same. What I said (rephrasing; I'm too lazy to look up what I really said) is essentially that a Symbol has one value: itself. If you will, its name. puts :wilbur.inspect # => :wilbur You can *convert* a Symbol to a string: puts :wilbur.to_s # => wilbur You can *convert* a Symbol to an integer value: puts :wilbur.to_i # => 23569 !! This value can change !! But both #to_s and #to_i are conversions, not attributes of the Symbol. The Symbol's only attribute is ... itself. Just like a Fixnum's only attribute is ... itself. puts 1.inspect # => 1 Look at what Symbol.instance_methods(false) returns: ["inspect", "to_int", "===", "to_s", "to_sym", "to_i", "id2name"] Symbol doesn't otherwise provide any methods not provided by Object (or Kernel), and most of those listed above are conversion methods. [...] Hopefully that's a bit clearer. It's not that different from Perl barewords. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca