Takeout 2020 の登壇資料 GitHub - ruby/typeprof: An experimental type-level Ruby interpreter for testing and understanding Ruby code typeprof/doc.ja.md at master · ruby/typeprof · GitHub [JA] Type Profiler: a Progress Report of a Ruby 3 Type Analyzer / Yusuke Endoh @mametter - YouTube Type Profiler: Ambitious Type Inference for Ruby 3
の挙動がちょっと変わります 今まではすでに include 済みのモジュールに対して include してもす でに include されているオブジェクトには反映されませんでした Ruby 3.0 ではあとから include した場合でもすでに include 済みのオ ブジェクトに反映されるようになりました 何をいってるのかわからないと思うのでサンプルコードを⾒てみよ う
X.ancestors に M2 が反映されるようになる module M; end class X include M end # この時点では M のみ反映されている p X.ancestors # => [X, M, Object, Kernel, BasicObject] module M2; end # M に対してあとから include したときの挙動が変わった M.include M2 # Ruby 2.7 : M2 は反映されない # Ruby 3.0 : M2 が反映される p X.ancestors # Ruby 2.7 => [X, M, Object, Kernel, BasicObject] # Ruby 3.0 => [X, M, M2, Object, Kernel, BasicObject]
" + super end end module M2 def to_s; "M2 -> " + super end end class X include M1 include M2 def to_s; "X -> " + super end end # このあたりは今までどおり期待する挙動 p X.ancestors # => [X, M2, M1, Object, Kernel, BasicObject] p X.new.to_s # => "X -> M2 -> M1 -> #<X:0x000055977aa63e68>"
で変わる Module#include の挙動 - Secret Garden(Instrumental) [Bug #9573] descendants of a module don't gain its future ancestors, but descendants of a class, do [Bug #17038] On master, ancestry edits can lead to duplicates in Module#ancestors