Symbol

Returns the integer corresponding to a symbol.

Use Fixnum#to_sym to obtain the symbol corresponding to this integer.

p :foo.to_i                         # => 8881
p :foo.to_i.to_sym                  # => :foo

In Ruby, reserved words, variable names, method names, and the like are controlled by these integers. Integers corresponding to objects (obtained via Object#object_id) and those corresponding to symbols are separate items.

Last updated