July 2007
Beginner to intermediate
176 pages
2h 30m
English
Ruby has a special object called a symbol. Symbols are like placeholders for identifiers and strings; they are always prefixed by a colon (:), such as :en and :logos. Most importantly, only one copy of the symbol is held in a single memory address, as long as the program is running. You don’t directly create a symbol by assigning a value to one. You create a symbol by calling the to_sym or intern methods on a string, or by assigning a symbol to a symbol:
name = "Brianna" name.to_sym # => :Brianna :Brianna.id2name # => "Brianna" name == :Brianna.id2name # => true
Read now
Unlock full access