Created
May 29, 2019 12:12
Star
You must be signed in to star a gist
Add smartmatch to an enum
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
| #!/usr/bin/env perl6 | |
| enum Keyword «a b c»; | |
| class C { | |
| has %.keywords; | |
| } | |
| my $c = C.new: :keywords{(a) => True}; | |
| Keyword.^add_multi_method("ACCEPTS", anon method (Keyword:D: C \c) { | |
| c.keywords{self}:exists | |
| }); | |
| Keyword.^compose; | |
| say $c ~~ a; | |
| say $c ~~ b; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment