Files
wren/test/language/constructor/new.wren
T

20 lines
435 B
Plaintext
Raw Normal View History

2013-11-29 15:21:36 -08:00
class Foo {
2015-03-14 12:45:56 -07:00
new { IO.print("none") }
new() { IO.print("zero") }
2014-01-05 12:27:12 -08:00
new(a) { IO.print(a) }
new(a, b) { IO.print(a + b) }
2013-11-29 15:21:36 -08:00
2014-04-03 07:48:19 -07:00
toString { "Foo" }
2013-11-29 15:21:36 -08:00
}
// Can overload by arity.
2015-03-14 12:45:56 -07:00
new Foo // expect: none
new Foo() // expect: zero
new Foo("one") // expect: one
new Foo("one", "two") // expect: onetwo
2013-11-29 15:21:36 -08:00
// Returns the new instance.
2015-03-14 12:45:56 -07:00
var foo = new Foo // expect: none
2014-01-05 12:27:12 -08:00
IO.print(foo is Foo) // expect: true
IO.print(foo.toString) // expect: Foo