Reputation: 4912
What is the difference between these three:
gets
- it gets a line with '\n'
gets.chomp
- it gets a line, but removes '\n'
Is that correct? What about gets.chomp!
?
Upvotes: 4
Views: 2448
Reputation: 118271
gets
- it gets a string with '\n'
at the end ( or better to say the line separator $/
at the end) , then #chomp
removes the \n
( or I would say the default value of $/
),and give you a new string. But #chomp!
did the same change in the receiver or the source string itself, on which you called #chomp!
method.
Note : #chomp!
is a bang version of #chomp
.
Upvotes: 7