O'Reilly logo

Ruby Cookbook, 2nd Edition by Leonard Richardson, Lucas Carlson

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

Chapter 23. User Interface

Ruby has libraries for attaching programs to the three main types of user interface. The web interface, Ruby’s most popular, is covered in depth in Chapters 16, 17, 18, and (to a lesser extent) 15. This chapter covers the other two interfaces: the terminal or console interface, and the graphical interface (GUI). We also cover some unorthodox interfaces (Recipe 23.11).

The terminal interface is a text-based interface usually invoked from a command line. It’s used by programs like irb and the Ruby interpreter itself. The terminal interface is usually seen on Unix systems, but all modern operating systems support it.

In the classic Unix-style “command-line program,” the user interface consists of the options used to invoke the program (Recipe 23.3), and the program’s standard input, output, and error streams (Recipe 23.1; also see Recipe 7.16). The Ruby interpreter is a good example of this kind of program. You can invoke the ruby program with arguments like -d and --version, but once the interpreter starts, your options are limited to typing in a Ruby program and executing it.

The advantage of this simple interface is that you can use Unix shell tools like redirection and pipes to connect these programs to each other. Instead of manually typing a Ruby program into the interpreter’s standard input, you can send it a file with the Unix command ruby < file.rb. If you’ve got another program that generates Ruby code and prints it to standard output, you can ...

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