From: Eric Russell Date: 2009-12-22T10:21:30+09:00 Subject: Re: Symbols vs. constants? There are some important difference between the two. While the object referred to by a constant will (in most cases) remain the same once its set, the object itself might change significantly. For example: AN_ARRAY = [] will point to that particular array, but if you add an object to that array there can be consequences. For example, if you use it as a key to a hash (which i don't recommend.). hash = {} hash [AN_ARRAY] = true hash << "string" hash[AN_ARRAY] => nil A symbol is immutable and therefore will always refer to the same element of a hash. On Dec 21, 2009, at 8:07 PM, Gennady Bystritsky wrote: > Constants are variables that can be assigned to any object (only > once). While symbols are immutable instances of class Symbol. Those > are 2 totally different concepts. > > Gennady. > > On Dec 21, 2009, at 4:57 PM, Sonja Elen Kisa wrote: > >> How are symbols and constant (capitalized) strings similar or >> dissimilar? They both seem to be used to store text that is not >> intended >> to change. In what situations should I use one or the other? How >> should >> I separate them in my brain? >> -- >> Posted via http://www.ruby-forum.com/. >> > >