mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-19 04:52:13 +02:00
Object Model example mixed old/new code/comments
This commit is contained in:
@@ -885,7 +885,7 @@ say_dyn(); #=> 1 100 We changed the value of $*dyn_scoped_2 in
|
|||||||
|
|
||||||
class Human {
|
class Human {
|
||||||
has Str $.name; # `$.name` is immutable but with an accessor method.
|
has Str $.name; # `$.name` is immutable but with an accessor method.
|
||||||
has Str $.bcountry; # Use `$!bplace` to modify it inside the class.
|
has Str $.bcountry; # Use `$!bcountry` to modify it inside the class.
|
||||||
has Str $.ccountry is rw; # This attribute can be modified from outside.
|
has Str $.ccountry is rw; # This attribute can be modified from outside.
|
||||||
has Int $!age = 0; # A private attribute with default value.
|
has Int $!age = 0; # A private attribute with default value.
|
||||||
|
|
||||||
@@ -911,12 +911,12 @@ class Human {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
## Create a new instance of Human class with $.attrib set to 5.
|
## Create a new instance of Human class.
|
||||||
## Note: you can't set private-attribute from here (more later on).
|
## Note: you can't set private-attribute from here (more later on).
|
||||||
my $person1 = Human.new(
|
my $person1 = Human.new(
|
||||||
name => "Jord",
|
name => "Jord",
|
||||||
bcountry = "Iceland",
|
bcountry = "Togo",
|
||||||
ccountry => "Iceland"
|
ccountry => "Togo"
|
||||||
);
|
);
|
||||||
|
|
||||||
say $person1.name; #=> Jord
|
say $person1.name; #=> Jord
|
||||||
|
Reference in New Issue
Block a user