Anonymous user
Create an object/Native demonstration: Difference between revisions
Create an object/Native demonstration (view source)
Revision as of 22:56, 26 October 2015
, 8 years ago→{{header|Perl 6}}
Line 292:
eval {...} called at test.pl line 66</lang>
=={{header|Perl 6}}==
{{works with|rakudo|
Here we use delegation to handle all the normal hash methods that we don't need to override to define our new class.
<lang perl6>class FixedHash {
has $.hash handles *;
method new(*@args) { self.bless: *, hash => Hash.new: @args }
method
$!hash.
}
method
}
Line 311:
say $fh<a b>; # 1 42
say $fh<c>; # Nil
$fh<c> = 43; # error
</lang>
{{out}}
<pre>(1 2)
(1
(1 42)
can't store value for unknown key
in block <unit> at native-demonstration.p6:17
in block at freezehash:21</pre>▼
Actually thrown at:
=={{header|Python}}==
|