Tsallaka zuwa abun ciki
Justice Tech School

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].inspect

Result

true
false
no
[:x, :y, :z]

Exercise

Write the symbol for ruby.

:

Quiz Test

Are two :ruby symbols the same object?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.