Ruby Symbols
A symbol is an immutable name written :name. Symbols are unique and fast, and are common as hash keys.
Example
a = :ruby
b = :ruby
puts a.equal?(b)
puts "ruby".equal?("ruby")
puts :a.to_proc.call("x") rescue puts "no"
puts %i[x y z].inspectResult
true false no [:x, :y, :z]
Exercise
Write the symbol for ruby.
:Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.