--00504502c1092b5a5f047b4776d4
Content-Type: text/plain; charset=ISO-8859-1

Symbols are like an identifier.  They're not really strings although they're
close to it, and they're generally used instead of strings when they're not
changing.

Symbols aren't re-created, that's the main benefit of using them over plain
old strings.  When you first declare :foo every time you use :foo again,
it's not re-created/re-instantiated... it's just looked up and re-used.

This is good and bad.  It's good because there's very little overhead to
using symbols compared to strings, but if you arbitrarily convert some
string into a symbol, it never leaves memory.  Watch converting user input
to a symbol!

In contrast a CONSTANT is a container for a value.  The value can be any
object.  This gives you a handy reference to the same instance of an object.

MY_CONSTANT  :one, :two, :three]

Hope that helps :)

Cheers
Daniel

On Tue, Dec 22, 2009 at 11:57 AM, Sonja Elen Kisa <sonja / kisa.ca> 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/.
>
>

--00504502c1092b5a5f047b4776d4--