Skip to content

Instantly share code, notes, and snippets.

@ChoHag
Created June 28, 2014 09:14
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 ChoHag/5bf910fa4b04d51bfa5f to your computer and use it in GitHub Desktop.
Save ChoHag/5bf910fa4b04d51bfa5f to your computer and use it in GitHub Desktop.
Fake hash
class fakehash {
has $.keys handles 'push';
has $.calculator = { $^a };
has $.null;
method postbrace ($lookup) {
$lookup ~~ $.keys.any ?? $!calculator($lookup) !! $.null;
}
}
sub postcircumfix:<{ }> (fakehash $bar, $lookup) {
$bar.postbrace($lookup);
}
say fakehash.new(calculator => sub {$^a~2}, keys => <<a b c d>>)<a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment