Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Proc#parameters
(?lambda: ::boolish) -> ::Method::param_types
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
-
4.0
-
Proc#parametersnow shows anonymous optional parameters as[:opt]instead of[:opt, nil], making the output consistent with when the anonymous parameter is required. [Bug #20974]
-
-
3.2
-
Proc#parametersnow accepts lambda keyword. [Feature #15357]
-