Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 8. Getting Things Done with Commands > The Command Pattern in the Wild

The Command Pattern in the Wild

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 Migrations

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.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial