From: Josef Wolf Date: 2009-09-09T06:30:23+09:00 Subject: Re: Zoomable TkCanvas? On Wed, Sep 09, 2009 at 05:29:47AM +0900, Joel VanderWerf wrote: Thanks for your patience with me, Joel! > Josef Wolf wrote: >> But how do I override the methods to create the items? In Perl/Tk, that >> would be easy, since item creation is done via canvas methods. But in >> Ruby/Tk, items are created via their own classes (e.g. TkcLine.new(args) >> or something). There don't seem to exist methods in the Canvas class to >> create items, which could easily be overridden. > > Maybe subclass (or delegate to) the Tk classes: > > class MyRectangle < TkcRectangle > def initialize(x,y,w,h) > super(...) # adjust args depending on zoom level etc. > end > end That would result in: - lots of new subclasses, polluting namespaces - lots of code duplication - it would not be a drop-in replacement: one would have to change the class names of the items when switching from standard canvas to the improved canvas Maybe extending TkcItem would be a better solution. Something like: class TkcItem alias orig_initialize initialize def initialize(parent, *args) # do whatever we need orig_initialize parent, args end end Opinions?