public Method

String.chop!

str.chop!    str or nil

Processes str as for String#chop, returning str, or nil if str is the empty string. See also String#chomp!.

Source Code

/*
*  call-seq:
*     str.chop!   => str or nil
*  
*  Processes <i>str</i> as for <code>String#chop</code>, returning <i>str</i>,
*  or <code>nil</code> if <i>str</i> is the empty string.  See also
*  <code>String#chomp!</code>.
*/

static VALUE
rb_str_chop_bang(str)
   VALUE str;
{
   if (RSTRING(str)->len > 0) {
       rb_str_modify(str);
       RSTRING(str)->len--;
       if (RSTRING(str)->ptr[RSTRING(str)->len] == '\n') {
           if (RSTRING(str)->len > 0 &&
               RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') {
               RSTRING(str)->len--;
           }
       }
       RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
       return str;
   }
   return Qnil;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.