Symbol (programming): Difference between revisions

Content deleted Content added
No edit summary
Examples: that's actually type coercion; rm a silly example
Line 64:
<source lang=ruby>
my_symbol = :a
my_symbol = :"aan identifier"
</source>
Symbols can be [[String interpolation|interpolated]]:
<source lang=ruby>
money = :"#{2+3} dollars" #=> :"5 dollars"
print "I have #{money}" #=> "I have 5 dollars"
</source>
Strings can be coerced into symbols, vice versa:
Line 82 ⟶ 77:
my_symbol.length #=> 11
my_symbol.class #=> Symbol
my_symbol.to_s.reverse.to_sym #=> :dlrow_olleh
</source>
Symbols as keys of an associative array: