That's what you see is probably indeed what the Ruby application produces. I have no idea how Ruby works, but for "usual" C programs stdout and stderr are typically not connected to each other, and stdout is typically buffered whereas stderr is not. So getting all stderr before the stdout buffer is flushed is not uncommon, also merging "packets" is not.

So to get what you want to you need either to flush after each output operation or to (a) un-buffer stderr and (b) synchronize stderr and stdout, both in the Ruby application.