最小代码:
#!/usr/bin/raku
class Widget {
submethod TWEAK(:$content, :$styles) {
say "t1\n";
}
}
class File is Widget {
submethod BUILD() {
say "b1";
}
}
my $xml = File.new();
和输出:
t1
b1
相关文档位于https://docs.raku.org/language/objects#Object_construction。我引用:“在调用 BUILD 方法之后,调用名为 TWEAK 的方法(如果它们存在),再次使用传递给 new 的所有命名参数”。
我正在使用 Fedora 32 附带的 rakudo 版本(rakudo-0.2020.02-1.fc32.x86_64 所以可能是今年 2 月)。