The chomp and chop Methods : chomp « String « Ruby






The chomp and chop Methods


# The chop (or chop!) method chops off the last character of a string
# the chomp (chomp!) method chomps off the record separator ($/) 

joe = <<limerick
T
q
limerick

puts joe

# Apply chomp! to remove the last record separator (\n)

joe.chomp! 

puts joe

 








Related examples in the same category

1.chomp! returns nil without altering the string because there is no record separator at the end of the string
2.chomp and chomp!