1
0
forked from Mirror/wren
Files
wren/test/constructor/new.wren
Bob Nystrom da4cadf16b Unify body handling.
Blocks, functions, and methods now have the same code for handling
their bodies.

This means that single-line methods work like single-line functions:
they return the result of their expression.
2014-04-03 07:48:19 -07:00

18 lines
380 B
Plaintext

class Foo {
new { IO.print("zero") }
new(a) { IO.print(a) }
new(a, b) { IO.print(a + b) }
toString { "Foo" }
}
// Can overload by arity.
new Foo // expect: zero
new Foo("one") // expect: one
new Foo("one", "two") // expect: onetwo
// Returns the new instance.
var foo = new Foo // expect: zero
IO.print(foo is Foo) // expect: true
IO.print(foo.toString) // expect: Foo