What does “Argument Error: wrong number of arguments (1 for 0)” mean?
When you define a function, you also define what info (arguments) that function needs to work. If it is designed to work without any additional info, and you pass it some, you are going to get that error.
Takes no arguments:
def dog end
def cat(name) end
When you call these, you need to call them with the arguments you defined.
dog #works fine cat("Fluffy") #works fine dog("Fido") #Returns ArgumentError (1 for 0) cat #Returns ArgumentError (0 for 1)
Check out the Ruby Koans to learn all this.
You passed an argument to a function which didn’t take any. For example:
def takes_no_arguments end takes_no_arguments 1 # ArgumentError: wrong number of arguments (1 for 0)
I assume you called a function with an argument which was defined without taking any.
def f() puts "hello world" end f(1) # <= wrong number of arguments (1 for 0)
If you change from using a lambda with one argument to a function with one argument, you will get this error.
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:
And then you got the message
ArgumentError: wrong number of arguments (0 for 1)
when you really meant: