Getting rid of ruby stdin/stdout buffering
If you're dealing with files, you probably want IO#fsync, which says:
Immediately writes all buffered data in ios to disk. Note that fsync differs from using IO#sync=. The latter ensures that data is flushed from Ruby’s buffers, but does not guarantee that the underlying operating system actually writes it to disk.
If you're just dealing with standard input and output, you might also try requiring io/console to see if using IO::console#ioflush gives you the behavior you need. The documentation says:
Flushes input and output buffers in kernel. You must require ‘io/console’ to use this method.
As an example, consider:
require 'io/console'
ARGF.each do |line|
$stdout.puts line
$stdout.ioflush
end