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 monkey-path add method

class Person
  def initialize(name : String, height : Float64)
    @name = name
    @height = height
  end
end
require "./person"

class Person
  def name
    return @name
  end
end

prs = Person.new(name: "Joe", height: 180)
puts prs # #<Person:0x7f3e27f68e40>
p! prs   # prs # => #<Person:0x7f3e27f68e40 @name="Joe", @height=180.0>

puts prs.name
require "./person"

class Person
  property email : String | ::Nil
end

prs = Person.new(name: "Joe", height: 180)
puts prs # #<Person:0x7f3e27f68e40>
p! prs   # prs # => #<Person:0x7f3e27f68e40 @name="Joe", @email=nil, @height=180.0>

prs.email = "foo@bar.com"
p! prs # prs # => #<Person:0x7f3e27f68e40 @name="Joe", @email="foo@bar.com", @height=180.0>