Skip to content

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

instance method

String#delete_prefix!

str.delete_prefix!(prefix) → self or nil

Deletes leading prefix from str, returning nil if no change was made.

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