- 此问题在此处已有答案**:
Why does Ruby compiler count expected number of arguments in this case as zero?(1个答案)
19小时前关门了。
您好,我刚刚收到以下错误:在"new"中:参数数目错误(给定7,应为0)(ArgumentError)
在 * 应用程序/服务/四分卫. rb * 中,我有:
class Quarterback
attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints,
def initialize(id, firstname, secondname, club, position, price, totalpoints)
@id = id
@firstname = firstname
@secondname = secondname
@club = club
@position = position
@price = price
@totalpoints = totalpoints
end
def info
"#{firstname} works for #{club} and has a cost of #{price}."
end
sparky = Quarterback.new('1', 'John', 'Edgar', 'Liverpool', 'Forward', '100', '38' )
puts sparky.info
end
谢谢你的帮助!
1条答案
按热度按时间guykilcj1#
这是因为在第2行的末尾有一个
,
:attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints,
将替换为
attr_accessor :id, :firstname, :secondname, :club, :position, :price, :totalpoints
要获得关于为什么会触发该错误的更详细解释,我建议阅读下面这个很棒的答案:https://stackoverflow.com/a/58176158/11330290