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.
String VS. Symbol
最新推荐文章于 2024-06-07 11:00:05 发布