public Method

String.chomp(...)

str.chomp(separator=$/)    new_str

Returns a new String with the given record separator removed from the end of str (if present). If $/ has not been changed from the default Ruby record separator, then chomp also removes carriage return characters (that is it will remove \n, \r, and \r\n).

"hello".chomp            #=> "hello"
"hello\n".chomp          #=> "hello"
"hello\r\n".chomp        #=> "hello"
"hello\n\r".chomp        #=> "hello\n"
"hello\r".chomp          #=> "hello"
"hello \n there".chomp   #=> "hello \n there"
"hello".chomp("llo")     #=> "he"

Source Code

/*
*  call-seq:
*     str.chomp(separator=$/)   => new_str
*  
*  Returns a new <code>String</code> with the given record separator removed
*  from the end of <i>str</i> (if present). If <code>$/</code> has not been
*  changed from the default Ruby record separator, then <code>chomp</code> also
*  removes carriage return characters (that is it will remove <code>\n</code>,
*  <code>\r</code>, and <code>\r\n</code>).
*     
*     "hello".chomp            #=> "hello"
*     "hello\n".chomp          #=> "hello"
*     "hello\r\n".chomp        #=> "hello"
*     "hello\n\r".chomp        #=> "hello\n"
*     "hello\r".chomp          #=> "hello"
*     "hello \n there".chomp   #=> "hello \n there"
*     "hello".chomp("llo")     #=> "he"
*/

static VALUE
rb_str_chomp(argc, argv, str)
   int argc;
   VALUE *argv;
   VALUE str;
{
   str = rb_str_dup(str);
   rb_str_chomp_bang(argc, argv, str);
   return str;
}
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.