构造函数重写
我上课了:
class One def initialize; end end
我需要使用我自己的构造函数创建一个新类,如下所示:
class Two < One def initialize(some) puts some super end end Two.new("thing")
但是当我启动代码时,我收到了一个错误:
thing test.rb:10:in `initialize': wrong number of arguments (1 for 0) (ArgumentError)
在这种情况下super
(没有括号)是一种特殊forms。 它使用原始参数调用超类方法。
而是试着打电话
super()