Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2017 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1eec3377fd8569b9a2330def847b05d9 to your computer and use it in GitHub Desktop.
Save anonymous/1eec3377fd8569b9a2330def847b05d9 to your computer and use it in GitHub Desktop.
perl6 attributes where constrain
#!/usr/bin/env perl6
use v6;
class Abc {
has Int $.a where { $^a == 0|1|2 } = 1;
has Int $.b where { $^b > 0 } = 5;
}
my $new = Abc.new( :1a, :10b );
$new.a.say;
$new.b.say;
$new = Abc.new( :3a, :10b );
$new.a.say;
$new.b.say;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment