Trait
A Trait represents the capabilities of an object. It describes fields and methods
an object should have, and can optionally define default behavior that a Class can
implement.
let Vehicle be trait with
name,
wheels, and
drive as method as
print "{own's name} go brr"
let Car be class implementing just Vehicle defined with
name as "car", and
wheels as 4
let car be new Car
do car's drive # car go brrTraits can also implement other traits, and in doing so may implement default values and behavior to fields and methods that aren't implemented in its parent traits.
let Health be trait with
health, and
heal as method with just amount as
update own's health to own's health plus amount
let Entity be trait implementing just Health with
name, and
health as 100
let Person be class implementing just Entity with just name defined with
name as name, and
greet as method as
print "{own's name} says hi"Traits can also be used to test the capabilities of an object.
if some_object implements Health do
some_object's heal 50Constructor
Creates a new Trait copying the given trait.
Getters
Returns a trait's property names as a list of strings.
Returns a trait's getter names as a list of strings.
Returns a trait's method names as a list of strings.
A getter that returns an Iterator to iterate over the trait properties.
print "hello world"