From: "Philip Mak" <pmak / aaanime.net>


> When working with a record that has various fields represented using a
> hash, do you prefer strings or symbols? Why?
>
> With strings, it's like this:
>
>     person = {
>         :name => "John Doe",
>         :age => 20
>     }
>
> With symbols, it's like this:
>
>     person = {
>         'name' => "John Doe",
>         'age' => 20
>     }

Your examples are the wrong way around!

> Symbols are one character shorter to type (:name v.s. 'name'). But,
> then I have to convert between symbols and strings sometimes using
> String#intern or Symbol#id2name. I do a lot of CGI programming; if a
> script like this is called:
>
> add_person.rhtml?name=John%20Doe;age=20
>
> then the "name" and "age" are given to me as strings, so I have to
> call String#intern in order to convert them into symbols first.

Given all this, I would use Strings if I were you.  For plain indices that
don't really need to be interpreted outside the hash, I use symbols.  I think
symbols are more efficient, too (but probably not if you're converting them to
strings all the time).

Gavin