-
-
Save zoffixznet/919f75cbe48b2aadeeedf75bc9434176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
has $.times = 0; | |
method meow { ++$!times } | |
} | |
my $o = Foo.new; | |
# method $o: calling | |
meow $o:; | |
# Standard calling | |
$o.meow; | |
$o.?meow; | |
$o.+meow; | |
$o.*meow; | |
# Hyper calling | |
$o».meow; | |
$o».?meow; | |
$o».+meow; | |
$o».*meow; | |
# Name-in-string calling | |
$o."meow"(); | |
$o.?"meow"(); | |
$o.+"meow"(); | |
$o.*"meow"(); | |
# Hyper name-in-string calling | |
$o»."meow"(); | |
$o».?"meow"(); | |
$o».+"meow"(); | |
$o».*"meow"(); | |
# methodop $variable calling | |
my $meth = $o.^lookup: 'meow'; | |
$o.$meth; | |
$o.?$meth; | |
$o.+$meth; | |
$o.*$meth; | |
# Hyper methodop $variable calling | |
$o».$meth; | |
$o».?$meth; | |
$o».+$meth; | |
$o».*$meth; | |
# $variable() calling | |
$meth($o); | |
$meth.($o); | |
$meth».($o); | |
# &variable calling | |
my &meth = $o.^lookup: 'meow'; | |
$o.&meth; | |
$o.?&meth; | |
$o.+&meth; | |
$o.*&meth; | |
# Hyper &variable calling | |
&meth = $o.^lookup: 'meow'; | |
$o».&meth; | |
$o».?&meth; | |
$o».+&meth; | |
$o».*&meth; | |
# &variable() calling | |
meth($o); | |
meth $o; | |
&meth($o); | |
&meth.($o); | |
&meth».($o); | |
# Meta assign op calling | |
my $v = $o; | |
$v .= meow; | |
# Function composition | |
($o.^lookup('meow') ∘ {$_})($o); | |
say "Saw {$o.times} different ways to call a method"; | |
# OUTPUT: Saw 43 different ways to call a method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment