[英]wrong number of arguments in Ruby
I need to randomly generate a name and capitalization.我需要随机生成一个名称和大小写。 I am getting the wrong number of arguments error
我收到错误数量的参数错误
" main.rb:21:in random_both': wrong number of arguments (given 0, expected 2) (ArgumentError) from main.rb:26:in
' " “ main.rb:21:in
random_both': wrong number of arguments (given 0, expected 2) (ArgumentError) from main.rb:26:in
的random_both': wrong number of arguments (given 0, expected 2) (ArgumentError) from main.rb:26:in
And I don't understand the error enough to know what I need to fix here.而且我对错误的理解不够充分,无法知道我需要在这里修复什么。 I would just like to know where this is going wrong.
我只想知道这是哪里出了问题。
I'm not looking for the answer necessarily but a push in the right direction would be lovely...我不一定要寻找答案,但朝着正确的方向推动会很可爱......
*note I can only amend *注意我只能修改
def random_both(random_name, random_case)
[random_name, random_case].sample
end
错误消息非常清楚:您使用 2 个参数定义了random_both
,但是在调用它时传递了 0 个参数。
You have to pass random_both
two arguments.您必须传递
random_both
两个参数。 You're currently passing zero arguments, like this: random_both()
.您当前正在传递零个参数,如下所示:
random_both()
。 But just passing random_both
two arguments won't work either because you're calling random_case
from random_both
and random_case
also takes an argument.但只是路过
random_both
因为你调用两个参数不会工作random_case
从random_both
和random_case
还需要一个参数。
I guess there is a misunderstanding of concepts.我猜是对概念的误解。
def random_both(random_name, random_case)
[random_name, random_case].sample
end
You are trying to use methods (random_name, random_case) as parameters.您正在尝试使用方法(random_name、random_case)作为参数。
Proceed to remove them from parameters and it should work.继续从参数中删除它们,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.