Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

32 lines (22 sloc) 0.535 kB
###
### class.nqp: Figure out how to write accessors and a custom new() method
###
# TO USE:
# $ parrot-nqp class.nqp
class Foo {
has $!name;
method new(:$name) {
my $class := pir::getattribute__PPs(self.HOW, "parrotclass");
Q:PIR{ $P0 = find_lex '$class'
self = new $P0 };
$!name := $name;
self;
}
method name ($name?) {
$!name := $name // $!name;
}
}
my $foo := Foo.new(:name('bar'));
say($foo.name);
$foo.name('quux');
say($foo.name);
Jump to Line
Something went wrong with that request. Please try again.