Created
October 24, 2015 19:27
-
-
Save anonymous/bcd7448642f4d93df39e 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
#!env perl6 | |
class Hello { ... } | |
class T { | |
has Real $.value is rw; | |
has Hello $.hello handles 'call_func'; | |
} | |
class Hello { | |
has Str $.name; | |
my %func_map = ( | |
mul => sub (Real $x, Real $y) { return $x * $y }, | |
add => sub (Real $x, Real $y) { return $x + $y }, | |
); | |
method call_func ($x, $y) { | |
dd %func_map; | |
my $t = %func_map{$.name}; | |
$t($x, $y); | |
} | |
} | |
my $x = Hello.new(:levels((3, 3, 3)), :name('add')); | |
my $t = T.new(:hello($x)); | |
say $t.call_func(3, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment