fork download
  1. require 'timeout'
  2.  
  3. class Float
  4. def times
  5. whole, frac = divmod(1)
  6. mean = whole.times.map { |i|
  7. start = Time.now
  8. yield i
  9. Time.now - start
  10. }.reduce(:+) / whole.to_f
  11.  
  12. return self if frac.zero?
  13. timeout(mean * frac) { yield whole } rescue nil
  14. self
  15. end
  16. end
  17.  
  18. 2.5.times do |i|
  19. "This is sentence ##{i.succ}.\n".each_char do |c|
  20. sleep 0.001 and print c
  21. end
  22. end
Success #stdin #stdout 0.01s 8464KB
stdin
Standard input is empty
stdout
This is sentence #1.
This is sentence #2.
This is sen