+ 1

I don't exactly understand what gets.chomp does in ruby.

I'm confused here. When we use gets let's say like this: Inf = gets Does the program consider whatever I submit AND the entire next line(space) as well as the value of inf? For instance if I submit "hello" , that won't be the only value of inf but the entire next empty line will also be considered the value of inf? I saw a similar example in the methods part in sololearn. Def greet(name=" ") If name =" " Puts "Greetings!" else Puts "Welcome, #{name}" end end greet(gets.chomp) When I used gets it didnt work as planned. I submitted nothing and yet it still didnt say "Greetings!" But said "welcome, " But when I used gets.chomp it worked.

28th Jun 2020, 10:33 AM
Einstein Shilly shally
Einstein Shilly shally - avatar
1 Réponse
0
Any input value, even nil values are different from no value at all. See this: https://code.sololearn.com/cROGMMwTo4n0/?ref=app
28th Jun 2020, 5:33 PM
Sandra Meyer
Sandra Meyer - avatar