end class D < C; end obj = D.new obj.c_instance_method • ·ͣΦϒδΣΫτͷࢀর͍ͯ͠ΔΫϥεΛ୳ࡧ͢Δ • ݟ͔ͭΒͳ͚ΕsuperclassΛ୳ࡧ͢Δ • ݟ͔ͭΕͦ͜Ͱ࣮ߦ͢Δ obj @my_var D Ϋϥεͷࢀর superclass ݟ͔ͭͬͨͷͰ ୳ࡧऴྃ C superclass Object superclass BasicObject c_instance_method
end class D < C def c_instance_method @my_var = 2 end end obj = D.new obj.c_instance_method obj @my_var D Ϋϥεͷࢀর superclass ઌʹݟ͚ͭΒΕΔͨΊ ͪ͜Β͕࣮ߦ͞ΕΔ C superclass Object superclass BasicObject c_instance_method c_instance_method
C include M def c_instance_method @my_var = 1 end end obj = C.new obj.m_method obj @my_var C Ϋϥεͷࢀর include includeͨ͠Ϟδϡʔϧ 1্ͭʹૠೖ͞ΕΔ M superclass Object superclass BasicObject m_method c_instance_method superclassΛ୳ࡧ͢Δ ΑΓલʹϞδϡʔϧ͕ ୳ࡧ͞ΕΔ
m2_method "m2_method" end end class C include M1 include M2 def c_instance_method @my_var = 1 end end obj = C.new obj.m1_method 13 ϞδϡʔϧΛ2ͭincludeͨ͠ͱ͖ obj @my_var Ϋϥεͷࢀর C c_instance_method M2 m2_method M1 m1_method Object BasicObject include include superclass superclass ݟ͔ͭͬͨͷͰ ୳ࡧऴྃ • ޙʹincludeͨ͠Ϟδϡʔϧ͕ ΑΓԼʹૠೖ͞ΕΔ • ઌʹ୳ࡧ͞ΕΔ • ͭ·ΓΦʔόʔϥΠυͰ͖Δ
C prepend M def c_instance_method @my_var = 1 end end obj = C.new obj.m_method obj @my_var M Ϋϥεͷࢀর prepend prependͨ͠Ϟδϡʔϧ Լʹૠೖ͞ΕΔ C superclass Object superclass BasicObject c_instance_method m_method