gpt4 book ai didi

ruby - 获取 `initialize' : wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app

转载 作者:数据小太阳 更新时间:2023-10-29 06:47:22 24 4
gpt4 key购买 nike

这是我的第一个 ruby 应用程序。我是一个堆栈溢出处女......当我运行以下程序时:

class NameApp

def intialize(name)
@names = []
end

def name_question
print "What is your name? "
answer = gets.chomp
@names += answer.to_s
puts "The number of characters in your name is " + names.length
end


def name_length
if @names.length > 25 then
print "Your name is longer than 25 characters."
else
print "Your name is too short."
end
end

end

name_app = NameApp.new("Test1")
name_app.class # => NameApp

name_app.name_question
name_app.name_length

我得到这个简单的错误消息结果:

name.rb:26:in `initialize': wrong number of arguments(1 for 0) (ArgumentError)
from nameapp.rb:26:in `new'
from nameapp.rb:26:in `<main>'

你能帮我解决问题吗?

最佳答案

你拼错了“initialize”。我刚开始的时候也这样做过几次,这很难调试。为什么 ruby​​ 没有将它命名为“init”,我永远不会知道。

关于ruby - 获取 `initialize' : wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com