Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
String#delete_suffix!
(::string suffix) -> self?
delete_suffix!(suffix) → self or nil
string.c
View on GitHub ↗
static VALUE
rb_str_delete_suffix_bang(VALUE str, VALUE suffix)
{
rb_len_t suffixlen;
str_modifiable(str);
suffixlen = deleted_suffix_length(str, suffix);
if (suffixlen <= 0) return Qnil;
return str_shrink(str, RSTRING_LEN(str) - suffixlen);
}
Like String#delete_suffix, except that self is modified in place; returns self if the suffix is removed, nil otherwise.
Related: see Modifying.
See also
#delete_suffix
#downcase
#delete_prefix!
#downcase!
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0