class A
def say
puts "i'm a"
end
end
class B < A
def say
#super 加入super不会被重载 会在调用父类后调用子类
puts "i'm b"
end
end
(B.new).say下面是单态方法的sample 单态方法其实就是属于对象而不属于类的方法 而且对象的单态方法可以覆盖类方法
class A
def say
puts "im a"
end
end
a = A.new
b = A.new
a.say # im a
b.say # im a
def b.say
puts "im b"
end
a.say #im a
b.say #im b

浙公网安备 33010602011771号