Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#add_trailing_separator
(untyped path) -> untyped
add_trailing_separator(p1)
pathname.c
View on GitHub ↗
static VALUE
add_trailing_separator(VALUE self, VALUE path)
{
if (RSTRING_LEN(check_strpath(path)) <= 0) return path;
rb_encoding *enc = rb_enc_get(path);
const char *name = RSTRING_PTR(path);
const char *end = RSTRING_END(path);
const char *top = rb_enc_path_skip_prefix(name, end, enc);
if (top < end && isdirsep(end[-1])) {
if (end[-1] == '/' || rb_enc_prev_char(top, end, end, enc) == end - 1)
return path;
}
return rb_str_cat_cstr(rb_str_dup(path), "/");
}
add_trailing_separator(path) -> path