symbols is placeholders for identifiers and strings. : Symbols « Language Basics « Ruby






symbols is placeholders for identifiers and strings.


# You can recognize symbols because they are always prefixed by a colon (:).
# You don't directly create a symbol by assigning a value to it. 
# You create a symbol by calling the to_sym or intern methods on a string or by assigning a symbol to a symbol. 


name = "myValue"
name.to_sym # => :myValue
:myValue.id2name # => "myValue"
name == :myValue.id2name # => true

 








Related examples in the same category

1.Ruby uses tons of symbols internally. To prove it, execute this line of Ruby code
2.Symbol in an array
3.id2name
4.Using Symbols as Hash Keys
5.object_id of three string with the same value
6.object_id of three symbols with the same name