Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
As you might expect from the discussion at the beginning of this chapter, the Command pattern pops up frequently in GUI frameworks. Both the TK and FXRuby GUI toolkits allow you to associate code block-style commands with GUI elements such as buttons and menu items. But the Command pattern also shows up in many other parts of the Ruby code base.
ActiveRecord[2] comes equipped with a classic example of an undo-able Command pattern implementation in the form of its migration facility. The ActiveRecord migration facility allows the programmer to define his or her database schema in a database-vendor-independent way—in Ruby, of course. The thing that makes migrations relevant here that each bit of the schema definition is organized as a command. Here, for instance, is a migration that creates a new database table called books:
[2] ActiveRecord, you will recall, is the database interface that Rails uses.