Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Proc#parameters
prc.parameters(lambda: nil) → array
proc.c
View on GitHub ↗
static VALUE
rb_proc_parameters(int argc, VALUE *argv, VALUE self)
{
static ID keyword_ids[1];
VALUE opt, lambda;
VALUE kwargs[1];
int is_proc ;
const rb_iseq_t *iseq;
iseq = rb_proc_get_iseq(self, &is_proc);
if (!keyword_ids[0]) {
CONST_ID(keyword_ids[0], "lambda");
}
rb_scan_args(argc, argv, "0:", &opt);
if (!NIL_P(opt)) {
rb_get_kwargs(opt, keyword_ids, 0, 1, kwargs);
lambda = kwargs[0];
if (!NIL_P(lambda)) {
is_proc = !RTEST(lambda);
}
}
if (!iseq) {
return rb_unnamed_parameters(rb_proc_arity(self));
}
return rb_iseq_parameters(iseq, is_proc);
}
Returns the parameter information of this proc. If the lambda keyword is provided and not nil, treats the proc as a lambda if true and as a non-lambda if false.
Example
prc = proc{|x, y=42, *other|} prc.parameters #=> [[:opt, :x], [:opt, :y], [:rest, :other]] prc = lambda{|x, y=42, *other|} prc.parameters #=> [[:req, :x], [:opt, :y], [:rest, :other]] prc = proc{|x, y=42, *other|} prc.parameters(lambda: true) #=> [[:req, :x], [:opt, :y], [:rest, :other]] prc = lambda{|x, y=42, *other|} prc.parameters(lambda: false) #=> [[:opt, :x], [:opt, :y], [:rest, :other]]
Ruby version changes
-
3.2
-
Proc#parametersnow accepts lambda keyword. [Feature #15357]
-
See also
#lambda?
#ruby2_keywords
#inspect
#source_location
also in
4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0