From ec8d0566372e7aea777c5735658ed64e8c59249b Mon Sep 17 00:00:00 2001 From: "Ryan A. Hagenson" Date: Tue, 19 Nov 2019 20:24:16 -0600 Subject: [PATCH] Add self-referential constructor call (#417) Fixes #284 by adding the `var a: T => a.create()` syntax after introduction of constructors. --- content/expressions/methods.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/content/expressions/methods.md b/content/expressions/methods.md index d1f0fce1..d05e3178 100644 --- a/content/expressions/methods.md +++ b/content/expressions/methods.md @@ -133,6 +133,16 @@ class Bar var b: Foo = a.from_int(3) ``` +We can even reuse the variable name in the assignment expression to call the constructor. + +```pony +class Bar + fun f() => + var a: Foo = a.create() +``` + +Here we specify that `var a` is type `Foo`, then proceed to use `a` to call the constructor, `create()`, for objects of type `Foo`. + ## Default arguments When defining a method you can provide default values for any of the arguments. The caller then has the choice to use the values you have provided or to provide their own. Default argument values are specified with a `=` after the parameter name.