Issue #15477 has been updated by majjoha (Mathias Jean Johansen).


For what it is worth, this appears to be an issue when dealing with curried procs as well.

``` ruby
curried_proc = ->(a, b) { a + b }.curry # => <Proc:0x00007fa7698e7700 (lambda)>
first = curried_proc.(1) # => <Proc:0x00007fa76991a0d8 (lambda)>
curried_proc.arity # => -1
first.arity # => -1
```

----------------------------------------
Feature #15477: Proc#arity returns -1 for composed lambda Procs of known arguments
https://bugs.ruby-lang.org/issues/15477#change-77120

* Author: robb (Robb Shecter)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
```
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.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>