Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Classes/Raku/classes-1.raku
Normal file
7
Task/Classes/Raku/classes-1.raku
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Camel { has Int $.humps = 1; }
|
||||
|
||||
my Camel $a .= new;
|
||||
say $a.humps; # Automatically generated accessor method.
|
||||
|
||||
my Camel $b .= new: humps => 2;
|
||||
say $b.humps;
|
||||
26
Task/Classes/Raku/classes-2.raku
Normal file
26
Task/Classes/Raku/classes-2.raku
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class Butterfly {
|
||||
has Int $!age; # With the ! twigil, no public accessor method is generated
|
||||
has Str $.name;
|
||||
has Str $.color;
|
||||
has Bool $.wings;
|
||||
|
||||
submethod BUILD(:$!name = 'Camelia', :$!age = 2, :$!color = 'pink') {
|
||||
# BUILD is called by bless. Its primary use is to to control
|
||||
# object initialization.
|
||||
$!wings = $!age > 1;
|
||||
}
|
||||
|
||||
method flap() {
|
||||
say ($.wings
|
||||
?? 'Watch out for that hurricane!'
|
||||
!! 'No wings to flap.');
|
||||
}
|
||||
}
|
||||
|
||||
my Butterfly $a .= new: age => 5;
|
||||
say "Name: {$a.name}, Color: {$a.color}";
|
||||
$a.flap;
|
||||
|
||||
my Butterfly $b .= new(name => 'Osgood', age => 4);
|
||||
say "Name: {$b.name}, Color: {$b.color}";
|
||||
$b.flap;
|
||||
Loading…
Add table
Add a link
Reference in a new issue