Symbol
A Symbol is a name: :width, :m3, :round. Two Symbols of the same name are the same
value, so they compare quickly and make good keys. Symbols name parameters
(param(:width, ...)), key Maps ({ width: 10 } is keyed by :width) and choose options
(stroke(1, cap: :round)).
A Symbol is written :name, or quoted for a name that isn’t an identifier: :"a b". A
double-quoted Symbol decodes its escapes and interpolates (:"part_#{i}"), a single-quoted one
doesn’t. %i[m3 m4] is the Array [:m3, :m4]. See Syntax.
As in Ruby, a Symbol reads as its name (puts, interpolation and join give m3) and
inspects with its colon (:m3). One that :name couldn’t read back inspects quoted. A Symbol
is never equal to a String: :m3 == "m3" is false.
size = :m3puts size # m3puts "thread #{size}" # thread m3puts size.inspect # :m3puts :"a b".inspect # :"a b"i = 2puts :"part_#{i}".inspect # :part_2puts size == :m3 # truesym.to_sThe Symbol’s name. Returns: String.
to_sym
Section titled “to_sym”sym.to_symThe Symbol itself (a String’s to_sym makes one). Returns: Symbol.
puts :m3.to_s.inspect # "m3"puts "m4".to_sym.inspect # :m4