Whats the difference between gets and gets.chomp | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Whats the difference between gets and gets.chomp

I really do not get the difference

23rd Mar 2018, 9:32 PM
Carlson T. Henson
Carlson T. Henson - avatar
1 Answer
+ 8
gets retrieves one line of text, *including* the Enter press at the end. For example, if you enter "Hello", and want to output it as: puts "Your word is \"#{word}\"." you would get: Your word is "Hello ". gets.chomp excludes the Enter press at the end. The same example above would instead output: Your word is "Hello".
23rd Mar 2018, 10:43 PM
Tamra
Tamra - avatar