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

Struct with default value

struct Person
  property name : String = ""
  property email : String?
end

prs = Person.new
p! prs
p! prs.name
p! prs.email

prs.name = "Foo"
prs.email = "new@foo.bar"
p! prs.name
p! prs.email
prs # => Person(@name="", @email=nil)
prs.name # => ""
prs.email # => nil
prs.name # => "Foo"
prs.email # => "new@foo.bar"