Skip to content

Commit

Permalink
Adds example for anon class, closes #1655
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed May 31, 2019
1 parent 15ce9aa commit 28f8591
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/Language/variables.pod6
Expand Up @@ -629,7 +629,18 @@ instance for classes or even sigilless variables.
Since these symbols are not installed in the scope, they can't be used by name.
They are useful, however, if they need to be assigned to an external variable
and they need to know their name themselves.
and they need to know their own name, but this can be retrieved using
introspection.
=for code
my $anon-class = anon class {
has $.bar;
method equal( ::?CLASS $foo ) {
return $foo.bar == $.bar;
}
};
say $anon-class.new( :3bar).equal( $anon-class.new( :3bar ) );
Expand Down

0 comments on commit 28f8591

Please sign in to comment.