Splitting string to integer from single-line user input?
Posted
by
pootzko
on Stack Overflow
See other posts from Stack Overflow
or by pootzko
Published on 2010-12-24T12:09:20Z
Indexed on
2010/12/24
12:54 UTC
Read the original article
Hit count: 190
I just started learning some ruby, and I want to do something like this:
print "Insert two numbers: "
a, b = gets.split(" ")
but I want to make a and b to be integers at the same time (in the same line).. If I add .to_i
to the second line (before or after split(" ")
), it doesn't work... so, how should I approach this? mapping, splitting, slicing? ok, I know I could use scanf, but other than scanf, how would I do this?
sorry for such a noobish question, but I just couldn't find a good enough answer only googling...
© Stack Overflow or respective owner