Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#delete_suffix!

str.delete_suffix!(suffix) → self or nil

Deletes trailing suffix from str, returning nil if no change was made.

Example
"hello".delete_suffix!("llo") #=> "he"
"hello".delete_suffix!("hel") #=> nil