String VS. Symbol

A string is a full blown Ruby object instance whereas a symbol is just
an identifier (or tag).

Symbols give you the equality operator (i.e. :foobar == :foobar)
without needing to instantiate string objects and perform a string
comparison.

If you don't need the String class's functionality and are just using
the string as an identifier then you probably just need a symbol
instead.

你可能感兴趣的:(Ruby)