Project

General

Profile

Actions

Feature #15477

open

Proc#arity returns -1 for composed lambda Procs of known arguments

Added by robb (Robb Shecter) almost 3 years ago. Updated over 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:90767]

Description

f = -> x { x + 2 }
g = -> x { x * 2 }
h = f << g

f.arity # => 1
g.arity # => 1
h.arity # => -1  THIS SHOULD BE 1 because h "knows" that it takes exactly 1 argument:
h.call  # => ArgumentError (given 0, expected 1)

Lambda Procs which are composed using << seem to partially lose knowledge of their arity. I don't know if this affects other procs, or the >> operator as well. The Proc#arity docs state that -1 is returned only when a variable or unknown number of arguments are expected by the Proc. But here, that's not the case.

Actions

Also available in: Atom PDF