lines = []
3.times do
lines << STDIN.readline.strip.to_i
end
lines.sort
EDIT:
If you are saying that you want it to accept an arbitrary number of inputs, you have a couple options: The simplest is to first input how many lines of input you have, like this:
num_lines = STDIN.readline.strip.to_i
lines = []
num_lines.times do
lines << STDIN.readline.strip.to_i
end
lines.sort
Or, if you don't know how many lines to expect, you have to have some way of signifying that the data is complete. For example, if you want to have an empty line mean the end of the data:
lines = []
STDIN.each_line do |line|
line.strip!
break if line == ''
lines << line.to_i
end
lines.sort
By the way, when the program is paused while awaiting input, this is not called an "infinite loop". It is "blocking" or simply "waiting for input".