From: Brian Candler Date: 2007-03-08T16:02:02+09:00 Subject: Re: Paul Graham explains Ruby symbols On Thu, Mar 08, 2007 at 02:46:43PM +0900, Chad Perrin wrote: > On Thu, Mar 08, 2007 at 04:21:10AM +0900, Bharat Ruparel wrote: > > I think of symbols is immutable strings that are useful only in > > referring to some values? Seems like a nice way for using pointers > > without all the warps? > > "Immutable strings" doesn't work so well, since a string literal is > "immutable" anyway. Well maybe that's technically right, in the sense that the source code itself is immutable. However, every time a string literal is 'executed' a new, mutable string object is instantiated: 5.times { puts "hello".object_id } So there's no way in practice to make use of the 'immutable' property you describe, because every String object your program sees is mutable. 5.times { a = "hello" a << "!" # changed it } Here's where I'd say a symbol is different: 5.times { a = :hello puts a.object_id # same every time round a << "!" # fails (symbol has no mutating methods) } Regards, Brian.