Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
class Bar { } # an empty class
|
||||
|
||||
my $object = Bar.new; # new instance
|
||||
|
||||
role a_role { # role to add a variable: foo,
|
||||
has $.foo is rw = 2; # with an initial value of 2
|
||||
}
|
||||
|
||||
$object does a_role; # compose in the role
|
||||
|
||||
say $object.foo; # prints: 2
|
||||
$object.foo = 5; # change the variable
|
||||
say $object.foo; # prints: 5
|
||||
|
||||
my $ohno = Bar.new; # new Bar object
|
||||
#say $ohno.foo; # runtime error, base Bar class doesn't have the variable foo
|
||||
|
||||
my $this = $object.new; # instantiate a new Bar derived from $object
|
||||
say $this.foo; # prints: 2 - original role value
|
||||
|
||||
my $that = $object.clone; # instantiate a new Bar derived from $object copying any variables
|
||||
say $that.foo; # 5 - value from the cloned object
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
my $lue = 42 but role { has $.answer = "Life, the Universe, and Everything" }
|
||||
|
||||
say $lue; # 42
|
||||
say $lue.answer; # Life, the Universe, and Everything
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
use MONKEY-TYPING;
|
||||
augment class Int {
|
||||
method answer { "Life, the Universe, and Everything" }
|
||||
}
|
||||
say 42.answer; # Life, the Universe, and Everything
|
||||
Loading…
Add table
Add a link
Reference in a new issue