Symbols vs strings vs?

Any rules or guidelines on when to use symbols vs strings? I'm not
sure as to the advantages of using symbols.

Thanks,
Joe

Joe Van Dyk wrote:

Any rules or guidelines on when to use symbols vs strings? I'm not
sure as to the advantages of using symbols.

Symbols are immutable strings. Every occurence of the same symbol
correspondes to the same single object, while every occurence of the
same string is a different object (with the same value). Thus symbols
are a bit faster and cheaper to use in things like case statements,
hash keys etc.
It's also usually a bit nicer to read in the code, as it signifies that
what you're looking it at is a unique identifier, rather than something
that can have a dynamic content.

HTH,
Assaph

It did help! Thanks.

ยทยทยท

On Thu, 3 Feb 2005 09:35:41 +0900, Assaph Mehr <assaph@gmail.com> wrote:

Joe Van Dyk wrote:
> Any rules or guidelines on when to use symbols vs strings? I'm not
> sure as to the advantages of using symbols.

Symbols are immutable strings. Every occurence of the same symbol
correspondes to the same single object, while every occurence of the
same string is a different object (with the same value). Thus symbols
are a bit faster and cheaper to use in things like case statements,
hash keys etc.
It's also usually a bit nicer to read in the code, as it signifies that
what you're looking it at is a unique identifier, rather than something
that can have a dynamic content.

HTH,
Assaph