27

我有一堂课:

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)
4

1 回答 1

52

super在这种情况下(不带括号)是一种特殊形式。它使用原始参数调用超类方法。

而是尝试调用

super()
于 2010-04-03T06:22:49.883 回答