From: Devin Mullins Date: 2005-12-29T11:31:22+09:00 Subject: Re: What is the difference between :foo and "foo" ? Jim Weirich wrote: >I'm not sure if this helped, or just muddied the water more. > > When I first was trying to learn about symbols, attempts to explain their "intentions" (as names of things, for example), rather than to explain what they are, just muddied the water for me. Sure, give me some advice on when and when not to use them, but also, tell me what they are, so I can decide for myself: - Like a string, but: - Object-level equality, so :foo.equal?(:foo) and not 'foo'.equal?('foo') - That means, with strings, if you say 'foo' 5 times in the code, you're creating 5 string objects, whereas with symbols, you're only creating one. - Share many properties with Fixnum (both being "immediate")-- immutable, no singleton classes, object equality, not picked up by ObjectSpace.each_object... - Not garbage collected. - Looks cooler -- by using a different syntax, you can give some visual distinction between your keys and your values, for instance. (Also, Johannes Friestad's explanation was pretty good, IMO.) Devin