Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Created June 24, 2019 03:28
Show Gist options
  • Save joseoliv/3c3062459ebc4f657cf90cb2c5a93790 to your computer and use it in GitHub Desktop.
Save joseoliv/3c3062459ebc4f657cf90cb2c5a93790 to your computer and use it in GitHub Desktop.
property
package metaobjectTest
@doc{*
Annotation 'property' should be attached to a field. It creates
get and, maybe, set methods for the field. There are four
possibilities for a field of type T:
- the field is declared with 'let' (or without 'var') and
. the field name stars with '_' like '_name'. Then method
func name -> T = _name;
is created;
. the field name does not start with '_' like 'name'.
Then method
func getName -> T = name;
is created;
- the field is declared with 'var' and
. the field name stars with '_' like '_name'. Then methods
func name -> T = _name;
func name: T other { self._name = other }
are created;
. the field name does not start with '_' like 'name'.
Then methods
func getName -> T = name;
func setName: T other { self.name = other }
are created;
*}
open
object Property
func run {
setTotal: 10;
assert getTotal == 10;
name: "Livia";
assert name == "Livia";
assert getMax == 0;
assert sister == "Carolina";
}
@property var Int total = 0;
@property var String _name = "";
@property let Int max = 0;
@property let String _sister = "Carolina";
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment