Main Content

puts - opposite of chomp in Ruby

Archive - Originally posted on "The Horse's Mouth" - 2006-12-15 04:56:03 - Graham Ellis

In Ruby, the chomp method removes the last character of a string if it's a line separator. The puts method adds a new line character on to the output unless there's one already present.

In Perl and other languages, a great deal of time and mental agility is expended in remembering where there are (and where there are not) end of line characters, and this practical ("pragmatic") approach in Ruby really makes life easy.