Skip to content

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

instance method

String#lstrip

lstrip → new_string

Returns a copy of self with leading whitespace removed; see Whitespace in Strings:

Example
whitespace = "\x00\t\n\v\f\r "
s = whitespace + 'abc' + whitespace
s        # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
s.lstrip # => "abc\u0000\t\n\v\f\r "

Related: String#rstrip, String#strip.

Ruby version changes

  1. 3.0
See also #lstrip! #ljust #lines #match also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0