End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Kernel#sub
sub(pattern, replacement) → $_
sub(pattern) {|...| block } → $_
ruby.c
View on GitHub ↗
static VALUE
rb_f_sub(int argc, VALUE *argv, VALUE _)
{
VALUE str = rb_funcall_passing_block(uscore_get(), rb_intern("sub"), argc, argv);
rb_lastline_set(str);
return str;
}
Equivalent to $_.sub(<i>args</i>), except that $_ will be updated if substitution occurs. Available only when -p/-n command line option specified.
See also
#String
#syntax_suggest_original_load
#srand
#syntax_suggest_original_require
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0