Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created February 22, 2013 20:09
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 jnthn/5016208 to your computer and use it in GitHub Desktop.
Save jnthn/5016208 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) is rw {
$!hash.exists($key) or warn "Cannot set non-existing key '$key'";
$!hash.at_key($key);
}
}
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