A Full Ruby/Gtk Application

In today's final example we'll bring together some of the Gtk features we have just learned about and will add a few new ones. The goal is to build a more versatile text editor around a Gtk::Text widget, giving it drop-down menus, global search and replace, and the ability to load and save files. There will be three classes in separate files, but one of those files, messagebox.rb, we have already written.

The top-level editor class is given in Listing 18.11.

Listing 18.11. editor.rb
 001: #!/usr/bin/env ruby 002: 003: require 'gtk'; include Gtk 004: require 'findbox' 005: require 'messagebox' 006: 007: class Editor < Window 008: def initialize(initial_filename = nil) 009: 010: super() 011: (ag = AccelGroup.new).attach(self) ...

Get Sams Teach Yourself Ruby in 21 Days now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.