From: jfn@... (Jeremy Nelson) Date: 2001-02-13T07:10:03+09:00 Subject: [ruby-talk:10760] How do I love ruby? [Because it's easy to fix things!] If anyone has read my messages, they have observed that I am in the midst of a saga of learning both Ruby *and* Tk at the same time. I should say that I am thouroughly enjoying this, and programming in Ruby is the most fun I have had in many, many years! (And I don't even hate Tk yet! =) One thing that I did notice about ruby/tk is that there is no parallel to the focusNext and focusPrev methods as in perl/tk. [1] I did find the 'tkmngfocus.rb' file in the ruby/tk library, but those functions do not seem to do what it is that I was trying to do. At the very best, I was able to get them to return a window path, but not to actually focus on that window. After pondering the circumstances for a while, (and a lot of digging around trying to learn how Ruby/Tk works), I realized that ruby can retroactively permit you to extend class definitions. Thus, whipping up the following modest functions: class TkObject def focusNext tk_call 'focus', tk_call 'tk_focusNext', @path end def focusPrev tk_call 'focus', tk_call 'tk_focusPrev', @path end end and putting this at the top of my source file, permits me to use the focusNext and focusPrev functions from *any* Tk widget automagically! The ability to "fix" things as needed on the fly is yet another reason why Ruby is quickly becoming my favorite language. Jeremy [1] My program needs to go to the next entry widget when the user presses the KP_Enter key. already does this, but I could not figure out how to alias a key to do what does, so I arrived at this solution.