You don't say what version of Ruby you're running. Also, your sample code doesn't demonstrate your use of gets
, which is important if you're having a problem with it. Nor does it show any sample of how you're trying to loop in the background as it waits for the user.
Based on your title and the use of Time, this is the minimum code I could think of that would start to test the problem:
time = Time.now
asdf = STDIN.gets
p Time.now - time
In Ruby 1.8.7:
test.rb(main):004:0> greg-mbp-wireless:Desktop greg$ rvm 1.8.7; rvm list
rvm rubies
=> ruby-1.8.7-p302 [ x86_64 ]
ruby-1.9.2-head [ x86_64 ]
ruby-1.9.2-p0 [ x86_64 ]
greg-mbp-wireless:Desktop greg$ irb -f test.rb
test.rb(main):001:0> time = Time.now
=> Sun Nov 21 13:24:58 -0700 2010
test.rb(main):002:0> asdf = STDIN.gets
=> "\n"
test.rb(main):003:0> p Time.now - time
3.802123
=> nil
In Ruby 1.9.2:
test.rb(main):004:0> greg-mbp-wireless:Desktop greg$ rvm 1.9.2; rvm list
rvm rubies
ruby-1.8.7-p302 [ x86_64 ]
ruby-1.9.2-head [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]
greg-mbp-wireless:Desktop greg$ irb -f test.rb
test.rb(main):001:0> time = Time.now
=> 2010-11-21 13:25:37 -0700
test.rb(main):002:0> asdf = STDIN.gets
=> "\n"
test.rb(main):003:0> p Time.now - time
3.578869
=> 3.578869
In each test I paused a couple seconds which is reflected in the Time calculations.
Besides p
returning a value in 1.9.2 and nil
in 1.8.7, I don't see any real difference. Show some sample of how you're looping in the background to do your calculations and I can expand the test code.