Question about symbols

Symbols are immutable memory-saving strings.

Say, you had a 100 objects that contained hashes of key/values.

if each of those objects had:

{ 'monkey' => true }

You'd be storing the string 'monkey' 100 times in memory. If you use

{ :monkey => true }

Then all the objects would be looking at the same symbol.

I also believe that symbol comparison is much faster than string
comparison, but I've never benchmarked it.

···

-----Original Message-----
From: Jacek Olszak [mailto:jacekolszak@o2.pl]
Sent: Wednesday, 9 November 2005 9:36 AM
To: ruby-talk ML
Subject: Question about symbols

Hi everyone...

I've just read the Pragmatic Programming Ruby book. But I
don't understand one thing : why should I use symbols (colon
sign before the variable name) ie. :name ?

Regards
Jacek
http://jacekolszak.blogspot.com

##############################################################
#######################
This email has been scanned by MailMarshal, an email content filter.
##############################################################
#######################

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################