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_prefix

str.delete_prefix(prefix) → new_str

Returns a copy of str with leading prefix deleted.

Example
"hello".delete_prefix("hel") #=> "lo"
"hello".delete_prefix("llo") #=> "hello"

Ruby version changes

  1. 3.0
See also #delete_prefix! #delete! #delete #delete_suffix also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1