Very cool, thanks to a comment from a reader I just learned about the Ruby $stdout and $stderr variables. In short, you can write to STDOUT and STDERR in Ruby using code like this:
$stdout.puts "stdout" $stderr.puts "stderr"
If you put those two lines in a Ruby script, and then run the script like this:
ruby test.rb > stdout 2> stderr
you'll find that the stdout and stderr files will contain the two different strings.