+ 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.
3 Réponses
+ 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.
0
So if I use gets there will be a line between each string I write and the .chomp removes that or what?
- 1
Have a look at this ruby lesson
https://www.sololearn.com/learn/Ruby/2764/