From: "boris_stitnicky (Boris Stitnicky)" Date: 2013-06-08T06:46:48+09:00 Subject: [ruby-core:55363] [ruby-trunk - Bug #8072] Method#arity for keyword arguments Issue #8072 has been updated by boris_stitnicky (Boris Stitnicky). +1 Ruby has outgrown #arity. Today, plain #arity should only return positive value, when the function has only compulsory ordered arguments. If there are any other arguments (optional ordered arguments, named arguments, splat-collected arguments...), #arity should return a negative value, meaning "Sorry, I give up, the negative integer I am returning to you does not convey full information on this function's arguments." However, I propose to make #arity work with one argument, and with terminology used int the return values of #parameters method: f = -> a, b, c=1, d=2, *e, f: 3, g: 4, **h {} f.parameters #=> [[:req, :a], [:req, :b], [:opt, :c], [:opt, :d], [:rest, :e], [:key, :f], [:key, :g], [:keyrest, :h]] f.arity #=> -3 f.arity( :req ) #=> 2 f.arity( :opt ) #=> 2 f.arity( :rest ) #=> 1 f.arity( :key ) #=> 2 f.arity( :keyrest ) #=> 1 g = -> req, **named_arguments {} g.arity #=> -2 g.arity( :req ) #=> 1 g.arity( :opt ) #=> 0 g.arity( :rest ) #=> 0 g.arity( :key ) #=> 0 g.arity( :keyrest ) #=> 1 ---------------------------------------- Bug #8072: Method#arity for keyword arguments https://bugs.ruby-lang.org/issues/8072#change-39782 Author: marcandre (Marc-Andre Lafortune) Status: Open Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: current: 2.1.0 ruby -v: r39608 Backport: I would expect the following two methods to have the same arity: def old_way(req, options = {}); end def new_way(req, **options); end method(:new_way).arity # => 1, should be -2 -- http://bugs.ruby-lang.org/