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#lstrip!

str.lstrip! → self or nil

Removes leading whitespace from the receiver. Returns the altered receiver, or nil if no change was made. See also String#rstrip! and String#strip!.

Refer to String#strip for the definition of whitespace.

Example
"  hello  ".lstrip!  #=> "hello  "
"hello  ".lstrip!    #=> nil
"hello".lstrip!      #=> nil
See also #lstrip #match #ljust #match? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0