Class monkey-path add method
examples/classes/person.cr
class Person def initialize(name : String, height : Float64) @name = name @height = height end end
examples/classes/use_person.cr
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
examples/classes/attribute_person.cr
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>