[英]ArgumentError: wrong number of arguments (given 0, expected 1) Ruby
ArgumentError: wrong number of arguments (given 0, expected 1).
ArgumentError:参数数量错误(给定 0,预期为 1)。
The code opens the file and looks at the paragraph and counts, the error is in the center of the code.代码打开文件,查看段落并计数,错误在代码的中心。 An error occurs when a method is called(1).
调用方法时发生错误 (1)。 I can't understand how to pass the argument methods.
我无法理解如何传递参数方法。
@books = "You can use this knowledge to create small tools that might help."
require "colorize"
class Filecalculation
def select
loop do
puts "# Will we search : calculation_lines paragraph(1)".cyan
print "\n>>>>>> ".yellow
input = gets.chomp
search_method = "calc_#{input}"
if (respond_to?(search_method))
I can't understand how to pass the argument to this place.我无法理解如何将参数传递给这个地方。
contents = send(search_method, @books)
else
puts "Unknown input: #{input.inspect}, method #{search_method} not defined."
end
end
end
# =================== calc_1 сounting words in Text File
def calc_1 paragraph
word_count = paragraph.split.length
puts "#{word_count} words"
end
end
Filecalculation.new.select
If you call send(search_method)
you call a method without arguments.如果你调用
send(search_method)
你调用一个没有参数的方法。 To pass arguments to the method being called, you need to pass them as next send
args:要将参数传递给被调用的方法,您需要将它们作为下一个
send
参数传递:
send(search_method, arg1, arg2)
in your case在你的情况下
send(search_method, paragraph)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.