Jump to content

Create an object/Native demonstration: Difference between revisions

m
→‎{{header|Perl 6}}: removed extraneous '*' from 'new' method
m (→‎{{header|Perl 6}}: removed extraneous '*' from 'new' method)
Line 292:
eval {...} called at test.pl line 66</lang>
=={{header|Perl 6}}==
{{worksWorks with|rakudo|20152016.10-2908}}
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 AT-KEY(FixedHash:D: $key is copy) is rw {
$!hash.EXISTS-KEY($key) ?? $!hash.AT-KEY($key) !! Failure.new(q{can't store value for unknown key});
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.