End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Pathname#sub
sub(*args)
ext/pathname/pathname.c
View on GitHub ↗
static VALUE
path_sub(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
if (rb_block_given_p()) {
str = rb_block_call(str, id_sub, argc, argv, 0, 0);
}
else {
str = rb_funcallv(str, id_sub, argc, argv);
}
return rb_class_new_instance(1, &str, rb_obj_class(self));
}
Return a pathname which is substituted by String#sub.
Example
path1 = Pathname.new('/usr/bin/perl') path1.sub('perl', 'ruby') #=> #<Pathname:/usr/bin/ruby>