Skip to content

Commit

Permalink
Add self-referential constructor call (#417)
Browse files Browse the repository at this point in the history
Fixes #284 by adding the `var a: T => a.create()` syntax after introduction of constructors.
  • Loading branch information
rhagenson authored and EpicEric committed Nov 20, 2019
1 parent db2afbb commit ec8d056
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions content/expressions/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ec8d056

Please sign in to comment.