how to create methods from arrays or hashes in perl6 <p>I am trying to add new methods to an object dynamicaly.</p> <p>Following code works just fine:</p> <pre><code>use SomeClass; my $obj = SomeClass.new; my $blah = 'ping'; my $coderef = method { say 'pong'; } $obj.^add_method($blah, $coderef); $obj.ping; </code></pre> <p>this prints "pong" as expected, whereas the following will not work as expected:</p> <pre><code>use SomeClass; my $obj = SomeClass.new; my %hash = one =&gt; 1, two =&gt; 2, three =&gt; 3; for %hash.kv -&gt; $k, $v { my $coderef = method { print $v; } $obj.^add_method($k, $coderef); } $obj.one; $obj.two; $obj.three; </code></pre> <p>will print either 111 or 333.</p> <p>Could anyone explain what i am missing or why the results are different from what i was expecting?</p>