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

Class with getters and setter (property)

  • property
  • getter
class Person
  property name : String

  def initialize(@name = "George")
  end
end

prs = Person.new(name: "Joe")
p! prs        # prs # => #<Person:0x7f8d0f266e80 @name="Joe">
puts prs.name # Joe
prs.name = "Jane"
puts prs.name # Jane

defaulty = Person.new
puts defaulty.name # George