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!
Additionally, the rarity of a sword can be improved by using the Ascender, or by increasing the luck in the Appraiser settings . " Boss sniping " is used by players to get Unique- or rarer swords, this is done by using the (now defunct) rare bosses spawns channel or joining servers that are close to 10 hours in age.
One of the early collectibles you'll need to find in Stray is Super Spirit Detergent, located in the Slums near the beginning of your adorable kitty journey. The merchant Azooz will sell you an Electric Cable you need to complete the fixing the Broken Tracker quest, but only if you find the detergent.
Every core booster pack's guaranteed to contain at least a Super Rare, in addition to eight Commons. Modern Super Rares have holofoil artwork, Level, and Attribute icons. Older Super Rares will only have holofoil artwork.
Regarding your real use case: there's no need to check the arguments yourself. Just call
super(arg1)
and Ruby will raise an ArgumentError
if the argument count doesn't match.
Due to some downvotes, I think I should answer your initial question.
How to get the arity of “super”?
Starting with Ruby 2.2, there's Method#super_method
and UnboundMethod#super_method
:
class A
def foo(arg)
end
end
class B < A
def foo(arg1, arg2)
end
end
B.instance_method(:foo).arity #=> 2
B.instance_method(:foo).super_method.arity #=> 1
From within B#foo
, you could write:
class B < A
def foo(arg1, arg2)
method(__method__).super_method.arity #=> 1
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With