In Ruby, the chomp method removes the
A record in the computer is a collection of data items arranged for processing.
This is shown in the illustration below:
The chomp method is declared as follows:
str.chomp
OR
str.chomp(substring)
The chomp method either takes no arguments or just one argument. In the case of an argument, a substring is specified to be removed from the string.
The chomp method returns the string with no record separator at the end of the string.
If chomp method will remove the carriage return characters from the string. These include \n, \r and \r\n.
The chomp method removes trailing newlines (\n) from a given string if $/ is empty.
The examples below show the use of the chomp method in Ruby:
#Example 1puts "bye\n".chomp#Example 2puts "bye\r\n".chomp#Example 3puts "bye".chomp('e')
Free Resources