Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
Proc#ruby2_keywords
static VALUE
proc_ruby2_keywords(VALUE procval)
{
rb_proc_t *proc;
GetProcPtr(procval, proc);
rb_check_frozen(procval);
if (proc->header.is_from_method) {
rb_warn("Skipping set of ruby2_keywords flag for proc (proc created from method)");
return procval;
}
switch (proc->block.type) {
case block_type_iseq:
if (ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_rest &&
!ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_post &&
!ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kw &&
!ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.has_kwrest) {
if (proc->header.is_refined) {
/* on a copy of this Proc's own: the block is shared with the
* source Proc until the first call, and the copy installed by
* it may be memoized and shared with sibling Procs */
const rb_iseq_t *copy =
rb_iseq_dup_with_independent_caches(proc->block.as.captured.code.iseq);
ISEQ_BODY(copy)->param.flags.ruby2_keywords = 1;
RB_VM_LOCKING() {
RB_OBJ_WRITE(procval, &proc->block.as.captured.code.val, (VALUE)copy);
}
}
else {
ISEQ_BODY(proc->block.as.captured.code.iseq)->param.flags.ruby2_keywords = 1;
}
}
else {
rb_warn("Skipping set of ruby2_keywords flag for proc (proc accepts keywords or post arguments or proc does not accept argument splat)");
}
break;
default:
rb_warn("Skipping set of ruby2_keywords flag for proc (proc not defined in Ruby)");
break;
}
return procval;
}
Deprecated: will be removed in Ruby 4.4. Use explicit delegation (*args, **kwargs) instead; it works correctly on Ruby 3.0 and later. See bugs.ruby-lang.org/issues/22205 for the schedule.
Marks the proc as passing keywords through a normal argument splat. This should only be called on procs that accept an argument splat (*args) but not explicit keywords or a keyword splat. It marks the proc such that if the proc is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the proc to other methods.
This should only be used for procs that delegate keywords to another method, and only for backwards compatibility with Ruby versions before 2.7.
Ruby version changes
-
4.1
-
Proc#ruby2_keywordsis deprecated and will be removed in Ruby 4.4. [Feature #22205]
-