On Mar 4, 2006, at 1:26 PM, Servando Garcia wrote:
>    I am a newbie to Ruby. I have been reading everything I can get  
> my hands on about Ruby. I understand what a symbol is and how it  
> saves memory space. I just can not seem to find any good reason to  
> use one. I am sure I am missing something. Would some one please  
> show me a good working example for using a symbol, please not the  
> "Foo Bar" example again.

IMHO, when your goal is to model distinct values but the actual bit  
patterns
are irrelevant then symbols are often the best approach.  When you  
goal is
to model a particular sequence of bytes or characters then strings  
are often
the best solution, especially when the sequence might change over time.

For example, if you want to record 'gender' you could model that in lots
of different ways:

	male	female
	----	------
	0	1
	1	0
	'm'	'f'
	'male'	'female'
	'mars'	'venus'
	-1	1
	1	-1
	true	false
	false	true
	:male	:female

In fact, the actual bit pattern is not important.  What is important
is that you have two unique objects and that they can be clearly mapped
to some external representation of male and female.  Symbols are  
perfect for
this because they implement value semantics (equality is based on  
identity)
and they also internalize the mapping to external strings.  If you  
choose
to use 1 and 0 instead you would still have to have some sort of  
conversion
table or code routine that mapped 1 to 'female' and 0 to 'male' (or vice
versa).  Use symbols and you get the conversion for 'free'.


Gary Wright