From: Mark Volkmann Date: 2006-04-07T22:59:56+09:00 Subject: Re: what are sympbols?!? On 4/7/06, Les Nightingill wrote: > Logan Capaldo wrote: > > > Likewise in ruby: > > > > { :class => "A" } > > > > 1.send(:class) > > > > The hash key has the same name as the method being sent via send, but > > the results are different. > > I too am struggling to understand, and this statement has me even more > confused! > > How can my results be predictable if :class isn't uniquely associated > with something (hash key, or method)? Doesn't this lead to ambiguities? Questions about symbols come up about every two weeks. You can find lots of good explanations in the archives. Here's a really brief one. Think of symbols as strings whose value never changes and where there are never two of them with the same value. Every time I use :foo in my code, it refers to the same Symbol object. Using symbols instead of strings saves space and it's faster to compare two symbols that to compare two strings since only their address in memory needs to be compared, not their individual characters. Some of the most common uses of symbols are - parameters to attr_accessor, attr_reader and attr_writer for generating corresponding get and set methods - keys in Hashes - method identifiers used with the Object send method -- R. Mark Volkmann Object Computing, Inc.