What does “wrong number of arguments (1 for 0)” mean in Ruby?

后端 未结 4 1488
渐次进展
渐次进展 2020-12-13 17:06

What does \"Argument Error: wrong number of arguments (1 for 0)\" mean?

4条回答
  •  甜味超标
    2020-12-13 17:46

    If you change from using a lambda with one argument to a function with one argument, you will get this error.

    For example:

    You had:

    foobar = lambda do |baz|
      puts baz
    end
    

    and you changed the definition to

    def foobar(baz)
      puts baz
    end
    

    And you left your invocation as:

    foobar.call(baz)
    

    And then you got the message

    ArgumentError: wrong number of arguments (0 for 1)
    

    when you really meant:

    foobar(baz)
    

提交回复
热议问题