From: cix Date: 2002-01-18T05:28:31+09:00 Subject: Re: Newbie question: RubyTk and Observer ? Hi, I am a newbie in ruby as well, but I have years of experience in OO and in perl (not too much OO/perl). At the moment I am learning ruby by developing a gui based project on my own. I have faced the same problems you describe. I think it could be useful to keep in touch. I have used perl/tk for one year more or less. In ruby I didn't want to repeat the experience, so I looked for anothe graphic toolkit (GT). I think Tk is ok, but it is lacking of some important things that you expect to be there in OO programming. Your problem and your solution are tipical examples. With ruby I tried FXRuby, Gtk+ and fltk. At the moment I use the latter because it is under developement, so that it is possible to help and to learn. So far I am happy with it. In any case each one of this GT let you can generate your events that are catched by the "mainloop" even if they are not GUI events (i.e. sockets, filehandlers,...) Using ruby you can use the global variables (starting with $) trick. You tie a global variable to a method. When the variable state changes, the method is called. In other words an Observer is implemented as build-in in the language. I hope this helps. By, cix On Thursday 17 January 2002 20:57, you wrote: > Greetings, > > Unix Sysadmin here, trying to become a decent programmer as well. In > the last three months or so, after wondering how the heck to make good > use of the Perl classes/objects Damian Conway's book taught me to > code, I've been devouring OO analysis/design books by Booch, > Jacobson, the Three Amigos and the Gang of Four. While I'm making use > of OO Perl in my current project at work, I've decided that I want to > learn Ruby. [ Dave and Andy: I bought the hardcopy; Too hard to read > a 21-inch CRT version in bed :o) ] > > So what I'm doing as a first project is that old first-quarter CS > staple, Conway's Life. It should be an interesting exercise in > refactoring, as the first versions will be a naive, slow > implementation with the universe being a 2D array of distinct Cell > objects; then as I learn more I'll move to a Flyweight pattern for the > cells and then a bitmapped universe, etc. etc. > > What I'm wondering about is how I'm going to display the results. I > was thinking of RubyTk, since I've dabbled a little in Tcl/Tk, but > what I can't figure out is how I can make a Tk window an Observer of > my universe. Tk's event-loop model is making me scratch my head. > Once I drop into Tk.mainloop, how the heck am I going to get any Life > processing done? There's got to be a simpler way, but the only thing > I can (naively?) think of right now is have the GUI running in one > thread and the CA stuff running in another, and have a timer event set > in the Tk.mainloop polling the Life universe to see if it's finished a > generation and is ready to display. There's got to be something less > "fraught with peril". How should I approach this? > > Thanks!