class Foo {
has Num $!num;
submethod BUILD(Num() :$num) {
$!num = $num
}
method gist { "{self.^name}.new($!num)" }
for Num.^methods -> &m {
my $name = &m.name;
::?CLASS.^add_method($name, my method (|c) {
say "calling: $!num.$name";
my \ret = $!num."$name"(|c);
return ::?CLASS.new: :num(ret) if ret ~~ Num;
ret
}) unless ::?CLASS.^lookup: $name
}
}
my $f = Foo.new: :num(42);
say $f;
say $f.^name;
my $r = $f.log10;
say $r;
say $r.^name;