+ 2

What is the difference between gets and gets.chomp in Ruby?

I am currently learning Ruby but i got stuck on this bit. I don't understand the difference between those 2. What do they do differently? I can't find a difference when i run it and see the outcome.

12th May 2018, 7:58 PM
Shyiva
3 ответов
+ 1
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. 
12th May 2018, 8:14 PM
᠌᠌Code X
᠌᠌Code X - avatar
0
So if I use gets there will be a line between each string I write and the .chomp removes that or what?
13th May 2018, 5:36 AM
Shyiva
- 1
Have a look at this ruby lesson https://www.sololearn.com/learn/Ruby/2764/
12th May 2018, 8:13 PM
MsJ
MsJ - avatar