Ruby Method arity
Today I learned that Method#arity does not consider blocks.
Also it returns negative with splat arguments.
Finally, all keyword arguments counts 1.
class Foo
def one; end
def two(a, b); end
def three(a, *b); end
def four(a, &b); end
def five(a, b:, c:); end
end
puts Foo.instance_method(:one).arity
# => 0
puts Foo.instance_method(:two).arity
# => 2
puts Foo.instance_method(:three).arity
# => -2
puts Foo.instance_method(:four).arity
# => 1
puts Foo.instance_method(:five).arity
# => 2
h/t @higgaion
Tweet