From: Logan Capaldo Date: 2006-01-18T09:41:44+09:00 Subject: Re: invalid_arity method similar to method missing ? On Jan 16, 2006, at 7:06 PM, Didier Prophete wrote: > all, > > Is there a function similar to method_missing when an existing > method is > called with the wrong number of arguments ? > > Suppose I have a class: > class MyClass > def my_func(var1, var2) > end > end > > And then I end up calling: > MyClass.new.my_func > > As expected, I end up getting an ArgumentError exception ('wrong > number > of arguments...). Is there a way to catch these... something like a > 'method_missing' (method_missing doesn't get called since the method > exists...), but which would work for wrong number of arguments. > > -Didier > > ps: obviously, for simple problems, I could end up using some default > argument values, but it won't work for the (real and more complex) > problem I am trying to solve... > > -- > Posted via http://www.ruby-forum.com/. > you could let your function be called with any number of arguments and then worry about it. Probably not what you were looking for though. eg def my_func(*args) var1, var2 = *args ... end