String vs Symbol
Category:
String
Is a sequence of bytes. The text is converted into those bytes usually by UTF-8 encoding.
String object are mutable.
Symbol
Symbol objects are immutable.
Same symbols, for example :book
and :book
, are in fact one object that is shared globally in all contexts for the duration of a program’s execution.
Thanks to that sharing symbols costs less memory than strings, but they cannot be collected by Garbage Collector once created.
Comparing symbols is quicker than comparing strings.