Say you are overwriting a method in a subclass with a different arity:
class A
def foo(arg) # arity is 1
# doing something here
end
end
class B < A
def foo(arg1, arg2) # arity is 2
super(arg1) # <- HERE
end
end
Is there a way to get the arity of super on line HERE?
(The real use case: I’m calling super knowing that the superclass doesn’t take any arguments. However, if the superclass implementation (in a gem) ever changes, I’d like to issue a warning.)
Thanks for your help!
Regarding your real use case: there’s no need to check the arguments yourself. Just call
and Ruby will raise an
ArgumentErrorif the argument count doesn’t match.Update
Due to some downvotes, I think I should answer your initial question.
Starting with Ruby 2.2, there’s
Method#super_methodandUnboundMethod#super_method:From within
B#foo, you could write: