【发布时间】:2014-07-23 10:48:42
【问题描述】:
两者有什么区别:
module Mod
def here
puts 'child'
end
end
class A
prepend Mod
def here
puts 'parent'
end
end
和
class A
def here
puts 'parent'
end
end
class B < A
def here
puts 'child'
end
end
或者换一种说法:派生类是否等同于添加子代码的模块?
【问题讨论】:
-
def do不是一个有效的语法.. 你应该给它一个名字..do是一个关键字,你不能给它一个方法名.. -
@ArupRakshit
do是一个有效的方法名称。 -
@sawa 我不知道...这不是缩进...为什么要尝试将方法名称命名为
do..无论如何。它的其他代码。我不会给它起一个像do这样的名字,因为do进入了 block 语法。 -
我将方法名称更改为
here以澄清问题的含义。
标签: ruby