0

Order of .chomp and .to_i

Does sit matter if the gets.chomp.to_i is written like that, or can you write it as gets.to_i.chomp

17th Nov 2016, 5:33 AM
rami alter
2 Réponses
0
Since chomp is only defined for strings, gets.to_i.chomp should raise an error. Also, due to the way to_i ignores whitespace, chomp shouldn't be needed if you're doing gets.to_i
18th Nov 2016, 4:10 PM
JayDepp
JayDepp - avatar
0
Dude i believe you have missed that its separate. gets.chomp and gets.to_i are the methods NOT necessarily gets.chomp.to_i OR the other way around. to_i method i believe automatically removes the newline from the user input.
22nd Nov 2016, 11:18 PM
Hanz Cliebb Tura
Hanz Cliebb Tura - avatar