メソッドの話
Perl6 になって,メソッドがよくわからんくなった.
あとメタプログラミングRuby を読んで,どこにメソッドが差してあるかが
気になってきた今日このごろ.
少し調べてみることにする.
class C11 { method f {say "C11"} } class C12 { method f {say "C12"} } class C21 { method f {say "C21"} } class C22 { method f {say "C22"} } class B1 is C11 is C12 { method f {say "B1"} } class B2 is C21 is C22 { method f {say "B2"} } class A is B1 is B2 { method f {say "A"} } my $obj = D.new; say $obj.WHAT; # D() say $obj.^parents(:tree).perl; # ([B1, [C11, [Any, [Mu]]], [C12, [Any, [Mu]]]], [B2, [C21, [Any, [Mu]]], [C22, [Any, [Mu]]]])
A -+- B1 -+- C11 | | | C12 | B2 -+- C21 | C22
role C11 { method f {say "C11"} } role C12 { method f {say "C12"} } role C21 { method f {say "C21"} } role C22 { method f {say "C22"} } role B1 does C11 does C12 { method f {say "B1"} } role B2 does C21 does C22 { method f {say "B2"} } class A does B1 does B2 { method f {say "A"} }
A -+- B1 -+- C11 | | | C12 | B2 -+- C21 | C22