VOOZH about

URL: https://apidock.com/ruby/String/lstrip!

⇱ String#lstrip! - APIdock


method

lstrip!

ruby latest stable - Class: String
lstrip!()
public

Removes leading whitespace from str, returning nil if no change was made. See also String#rstrip! and String#strip!.

Refer to strip for the definition of whitespace.

" hello ".lstrip! #=> "hello "
"hello ".lstrip! #=> nil
"hello".lstrip! #=> nil
static VALUE
rb_str_lstrip_bang(VALUE str)
{
 rb_encoding *enc;
 char *start, *s;
 long olen, loffset;

 str_modify_keep_cr(str);
 enc = STR_ENC_GET(str);
 RSTRING_GETMEM(str, start, olen);
 loffset = lstrip_offset(str, start, start+olen, enc);
 if (loffset > 0) {
 long len = olen-loffset;
 s = start + loffset;
 memmove(start, s, len);
 STR_SET_LEN(str, len);
#if !SHARABLE_MIDDLE_SUBSTRING
 TERM_FILL(start+len, rb_enc_mbminlen(enc));
#endif
 return str;
 }
 return Qnil;
}

Related methods