O'Reilly logo

Text Processing with Ruby by Rob Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple Output

At its most basic, standard output is familiar to anyone who’s written a Ruby script before. The simplest hello world script outputs its message to standard output, and when run from the command line we see that message printed to our screens.

Just like standard input, standard output has two references in Ruby: its constant, STDOUT, and the global variable $stdout. Just like with standard input, you should prefer the latter since it respects reassignment.

If you want to output to standard output, it’s generally not necessary to state this explicitly. The two most used methods for outputting text in Ruby, print and puts, both operate on $stdout implicitly, so while we could call:

 
$stdout.puts ​"Hello, world!"

it’s not necessary, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required