Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created November 21, 2016 19:08
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 zoffixznet/4cc505781009411d4f1b50915b0a5df9 to your computer and use it in GitHub Desktop.
Save zoffixznet/4cc505781009411d4f1b50915b0a5df9 to your computer and use it in GitHub Desktop.
class CardWorks1 {
# subset's block uses { ... } instead of WhateverCode
my @faces = <2 3 4 5 6 7 8 9 10 Jack Queen King Ace>;
subset Face of Str where { $_ eq @faces.any };
has Face $.face is required;
}
class CardWorks2 {
# Array is assigned to in a BEGIN
BEGIN my @faces = <2 3 4 5 6 7 8 9 10 Jack Queen King Ace>;
subset Face of Str where * eq @faces.any;
has Face $.face is required;
}
class CardBroken {
# if change @faces.say; we'll see array is empty during the check
my @faces = <2 3 4 5 6 7 8 9 10 Jack Queen King Ace>;
subset Face of Str where * eq @faces.any;
has Face $.face is required;
}
dd CardWorks1.new: :face<2>; # Success
dd CardWorks2.new: :face<2>; # Success
dd CardBroken.new: :face<2>; # Type check fail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment