メタプログラミングRuby 四日目を読んだ
で,
- 特異クラスは たぶん Role を差してやればいいと思う
- alias は,なんかいい方法があるんだろうか.next とか?
- my &old_name := &thermo; &thermo = sub {}; とか普通にできるみたい(S06)
# our にすれば,class スコープに augment class MyClass { our $c; method c { $c } } # 別名を付けて,上書き augment class Str { .^add_method('real_chars', &chars); method chars { .real_chars > 5 ?? 'long' !! 'short' } }
メタプログラミングRuby
posted with amazlet at 11.02.20