In Ruby, `:name` is a Symbol object, not a string or a variable. The leading colon creates a symbol literal; quotes allow spaces, as in `:"full name"`. A string becomes a symbol with `to_sym` or `intern`, and a symbol becomes a string with `to_s`. section 8.2
A symbol is immutable: `:abc` cannot acquire another character; `:abcd` is a different symbol. It is also unique: every occurrence of `:xyz` denotes the same object, whereas separate evaluations of `"xyz"` produce separate strings. Ruby therefore has no `Symbol#new` constructor. Think of symbols as integer-like values written with characters, rather than editable pieces of text. section 8.2.1 section 8.2.4
>> "xyz".object_id
=> 2707250
>> "xyz".object_id
=> 2704780
>> :xyz.object_id
=> 160488
>> :xyz.object_id
=> 160488
Compare the object IDs: the two string literals differ, but repeated uses of `:xyz` identify the same object. section 8.2.1
Symbols can look stringlike without becoming mutable strings. For example, `:david.upcase` returns `:DAVID`, while `:david[2]` returns the string `"v"`. The original symbol stays unchanged; there is no in-place `upcase!` counterpart for it. section 8.2.4
Two common places to use symbols are:
- Method-name arguments: `"abc".send(:upcase)` invokes `upcase`; `attr_reader :age` likewise supplies a name. If a method already accepts a string, converting that string with `to_sym` first is usually unnecessary. section 8.2.3
- Hash keys: `{ name: "Joe", age: 44 }` uses symbols as keys, so the age is retrieved with `hash[:age]`. section 8.2.3
A Symbol object is distinct from an identifier, even when both have the same spelling. Ruby uses symbols internally to track names of variables, methods, and constants; `Symbol.all_symbols` exposes the resulting symbol table. Be careful when probing it: writing `:abc` in an inclusion test itself introduces that symbol, so the test cannot establish whether `abc` was already present. section 8.2.2




