End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#rstrip
str.rstrip → new_str
string.c
View on GitHub ↗
static VALUE
rb_str_rstrip(VALUE str)
{
rb_encoding *enc;
char *start;
long olen, roffset;
enc = STR_ENC_GET(str);
RSTRING_GETMEM(str, start, olen);
roffset = rstrip_offset(str, start, start+olen, enc);
if (roffset <= 0) return str_duplicate(rb_cString, str);
return rb_str_subseq(str, 0, olen-roffset);
}
Returns a copy of the receiver with trailing whitespace removed. See also String#lstrip and String#strip.
Refer to String#strip for the definition of whitespace.
Example
" hello ".rstrip #=> " hello" "hello".rstrip #=> "hello"
Ruby version changes
-
3.0
-
The following methods now return or yield
Stringinstances instead of subclass instances when called on subclass instances: [Bug #10845]
-