继承心得
继承关系及 ancestors
module A
def do_something
puts 'A -> do_something'
super
end
end
module B
def do_something
puts 'B -> do_something'
super
end
end
module C
def do_something
puts 'C -> do_something'
super
end
end
class Parent
def do_something
puts 'Parent -> do_something'
end
end
class Child < Parent
include A
include B
include C
end
p Child.ancestors
# => [Child, C, B, A, Parent, Object, Kernel, BasicObject]
Child.new.do_something
# 输出 =>
#
# C -> do_something
# B -> do_something
# A -> do_something
# Parent -> do_somethinginherited 方法
extend 方法
最后更新于