Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create empty hash

  • empty?
phone_of = {} of String => String
puts phone_of.empty?

phone_of["Jane"] = "123"
phone_of["Jack"] = "456"

# phone_of["Narnia"] = 42
# Error: no overload matches 'Hash(String, String)#[]=' with types String, Int32

puts phone_of
puts phone_of.empty?
phone_of = {} of String => String | Int32
phone_of["Jane"] = "123"
phone_of["Jack"] = "456"

phone_of["Narnia"] = 42

# phone_of["is_it_true?"] = true
# Error: no overload matches 'Hash(String, Int32 | String)#[]=' with types String, Bool

puts phone_of
phone_of = {} of String => String | Int32 | Bool
phone_of["Jane"] = "123"
phone_of["Jack"] = "456"

phone_of["Narnia"] = 42

phone_of["is_it_true?"] = true

puts phone_of