Ruby Cookbook - problem recipe

L

Len Lawrence

Skipping through the Ruby Cookbook (Carlson & Richardson) I tried out the
rubyTk stopwatch program, which worked fine, then tried the GTK version.
I typed it in more or less verbatim but could not run it because the
menuspec which is given as an array (see below) could not be converted to
a string by the Gtk::ItemFactory create_items method.

Extract from the initialize method of the Stopwatch class:

menu_factory = Gtk::ItemFactory.new( Gtk::ItemFactory::TYPE_MENU_BAR,
'<main>', nil )
menuspec = [
[
[ '_Program' ],
[ '/Program/_Start', '<Item>', nil, nil, lambda { start } ],
[ '/Program/S_top', '<Item>', nil, nil, lambda { stop } ],
[ '/Program/_Exit', '<Item>', nil, nil,
lambda { Gtk.main_quit } ]
],
[
[ '_Reset' ],
[ '/Reset/_Reset Stopwatch', '<Item>', nil, nil,
lambda { reset } ]
]
]

menu_factory.create_items( menuspec )

The error message specifies the last line here as the problem. Have I
missed something obvious? The OReilly website lists errata for the book
but nothing for page 806 where this code snippet comes from. Should I be
looking for version mismatches in GTK2 perhaps?

Len
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top