1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/doc/string/chop.rdoc
Burdette Lamar 465edb96f0
[DOC] Enhanced RDoc for String (#5707)
Treated:

    #chomp
    #chomp!
    #chop
    #chop!
2022-03-24 19:40:58 -05:00

16 lines
578 B
Text

Returns a new string copied from +self+, with trailing characters possibly removed.
Removes <tt>"\r\n"</tt> if those are the last two characters.
"abc\r\n".chop # => "abc"
"тест\r\n".chop # => "тест"
"こんにちは\r\n".chop # => "こんにちは"
Otherwise removes the last character if it exists.
'abcd'.chop # => "abc"
'тест'.chop # => "тес"
'こんにちは'.chop # => "こんにち"
''.chop # => ""
If you only need to remove the newline separator at the end of the string, String#chomp is a better alternative.