[ruby-core:115155] [Ruby master Misc#19971] Confusing arity of a Proc with implicit rest parameter
From:
"shan (Shannon Skipper) via ruby-core" <ruby-core@...>
Date:
2023-10-24 20:32:23 UTC
List:
ruby-core #115155
Issue #19971 has been updated by shan (Shannon Skipper).
Docs say it's intended, since #arity "returns -n-1, where n is the number of mandatory arguments, with the exception for blocks that are not lambdas and have only a finite number of optional arguments; in this latter case, returns n." A Proc in this case isn't a lambda, so it returns `n` rather than `-n-1`. Procs have loose arity, like blocks, unlike lambdas.
----------------------------------------
Misc #19971: Confusing arity of a Proc with implicit rest parameter
https://bugs.ruby-lang.org/issues/19971#change-105062
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
----------------------------------------
I've noticed that such proc `proc { |a,| }` has arity `1` that means 1 required parameter, but behaves like there is a rest parameter (`proc { |a, *| }`) that has arity `-2` (that means 1 required parameter + rest parameter).
So I am wondering whether it's intentional behaviour and what the rational is behind it.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/