summaryrefslogtreecommitdiff
path: root/doc/string/chop.rdoc
blob: 8ef82f8a492548c02fa1276d1e3f86ca34e469cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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.