Mega Code Archive

 
Categories / Ruby / String
 

Chop removes trailing character or line terminator (n, r, or rn)

s = "hello\n" s.chop!              # => "hello": line terminator removed. s modified. s.chop               # => "hell": last character removed. s not modified. "".chop              # => "": no characters to remove "".chop!             # => nil: nothing changed