【发布时间】:2019-02-03 05:58:25
【问题描述】:
我想从我写在不同文件上的类中实例化一个对象。我得到的是wrong number of arguments (given 1, expected 0) (ArgumentError)
这里是主要代码
# ./lib/parking_lot
require_relative './lot.rb'
class ParkingLotInterface
def initialize(input: $stdin, output: $stdout)
@input, @output = input, output
@lot = nil
end
def prompt_input
@lot = Lot.new(10)
end
end
parking_lot_interface = ParkingLotInterface.new(input: $stdin, output: $stdout)
parking_lot_interface.prompt_input
这里是对象类
# ./lib/lot
class Lot
attr_reader :slots,
def initialize(size)
@slots = Arrays.new(size)
end
end
在我尝试实例化一个新的 Lot 对象的那一行引发了错误。查看互联网,有同样问题的人被告知他们没有在课堂上指定def initialize,或者他们输入错误。然而,我照他们说的做了,我还是面对wrong number of arguments (given 1, expected 0) (ArgumentError)
我做错了什么?
【问题讨论】: