Reading several data entries per line from screen

Is there a single, easy method in Ruby that will let me read multiple
numbers from the screen directly into multiple variables?

For instance, say I have two variable called "age" and "weight", and
query the user to enter them on the same line. In FORTRAN I'd just say

READ(*,*) age, weight

and when the user enters "20, 200" they are put to age and weight, as
real variables. Can I do a similar thing in Ruby?

I did create a method that will parse the string read by "gets" into
elements of an array, but there must be a simpler way to do this that I
am missing.

···

--
Posted via http://www.ruby-forum.com/.

Is this what you are looking for?

name, age, weight = gets.split(/,/)
puts name
puts age
puts weight

Harry

···

On 2/3/07, Alex DeCaria <alex.decaria@millersville.edu> wrote:

Is there a single, easy method in Ruby that will let me read multiple
numbers from the screen directly into multiple variables?

For instance, say I have two variable called "age" and "weight", and
query the user to enter them on the same line. In FORTRAN I'd just say

READ(*,*) age, weight

--

Is this what you are looking for?

name, age, weight = gets.split(/,/)
puts name
puts age
puts weight

Harry

Yes, Thank You!

···

--
Posted via http://www.ruby-forum.com/\.