@@ -854,18 +854,17 @@ def ===(other)
854
854
end
855
855
856
856
def arity
857
- accepts_infinite_arguments? ? Float ::INFINITY : parts . length
858
- end
859
-
860
- private
861
-
862
- def accepts_infinite_arguments?
863
- parts . any? do |part |
864
- part . is_a? ( ArgStar ) || part . is_a? ( ArgsForward ) ||
865
- (
866
- part . is_a? ( BareAssocHash ) &&
867
- part . assocs . any? { |p | p . is_a? ( AssocSplat ) }
868
- )
857
+ parts . sum do |part |
858
+ case part
859
+ when ArgStar , ArgsForward
860
+ Float ::INFINITY
861
+ when BareAssocHash
862
+ part . assocs . sum do |assoc |
863
+ assoc . is_a? ( AssocSplat ) ? Float ::INFINITY : 1
864
+ end
865
+ else
866
+ 1
867
+ end
869
868
end
870
869
end
871
870
end
@@ -8383,18 +8382,24 @@ def ===(other)
8383
8382
8384
8383
# Returns a range representing the possible number of arguments accepted
8385
8384
# by this params node not including the block. For example:
8386
- # def foo(a, b = 1, c:, d: 2, &block)
8387
- # ...
8388
- # end
8389
- # has arity 2..4
8385
+ #
8386
+ # def foo(a, b = 1, c:, d: 2, &block)
8387
+ # ...
8388
+ # end
8389
+ #
8390
+ # has arity 2..4.
8391
+ #
8390
8392
def arity
8391
8393
optional_keywords = keywords . count { |_label , value | value }
8394
+
8392
8395
lower_bound =
8393
8396
requireds . length + posts . length + keywords . length - optional_keywords
8394
8397
8395
8398
upper_bound =
8396
- lower_bound + optionals . length +
8397
- optional_keywords if keyword_rest . nil? && rest . nil?
8399
+ if keyword_rest . nil? && rest . nil?
8400
+ lower_bound + optionals . length + optional_keywords
8401
+ end
8402
+
8398
8403
lower_bound ..upper_bound
8399
8404
end
8400
8405
0 commit comments