-
-
Save Ovid/97d7bea032c00a8ccd44 to your computer and use it in GitHub Desktop.
A better example?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee { | |
# Rat is a rational number. No more floating point errors | |
subset Salary of Rat where * > 0; | |
subset NonEmptyString of Str where * ~~ /\S/; # at least one non-space character | |
has NonEmptyString $.name is rw; | |
has NonEmptyString $.surname is rw; | |
has Salary $.salary is rw; | |
method Str { | |
return qq:to[END]; | |
Name: {$.name} | |
Surname: {$.surname} | |
Salary: {$.salary} | |
END | |
} | |
} | |
my $employee = Employee.new(); | |
given $employee { | |
.name = 'Sally'; | |
.surname = 'Ride'; | |
.salary = 200.0; | |
} | |
say "$employee"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment