Skip to content

Instantly share code, notes, and snippets.

@TimToady
Created February 22, 2013 19:55
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 TimToady/5016105 to your computer and use it in GitHub Desktop.
Save TimToady/5016105 to your computer and use it in GitHub Desktop.
class FreezeHash {
has $.hash handles *;
method new(*@args) { self.bless: *, hash => Hash.new: @args }
method at_key(FreezeHash:D: $key is copy) {
$!hash.exists($key) or warn "Cannot set non-existing key '$key'";
nextsame;
}
}
my $fh = FreezeHash.new: "a" => 1, "b" => 2;
say $fh.perl;
say $fh<a>;
$fh<c> = 3;
say $fh<c>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment