From: Robert Dober Date: 2008-03-03T20:09:44+09:00 Subject: Re: Understanding ruby classes On Mon, Mar 3, 2008 at 9:07 AM, Damjan Rems wrote: > > This question is all about me not understanding how ruby classes work. > > I have three print classes. myPrint which is abstract class and > implements common methods for other two classes which are myPrint2PDF > and myPrint2HTML. Which means it just factorizes work, I suggest you make it a module then module MyPrint... > They implement all the troubles of output to PDF or > HTML format. Without too much code, implementation looks like this: > > class myPrint > def printHDR > end > .... > end > > class myPrint2PDF include MyPrint include Workerbee ## see below > .... > end > > class myPrint2HTML include MyPrint include Workerbee > .... > end > > > Then I have fourth class which implements the job which has to be done. Should probably still be a module, let us name it Workerbee > > class myPrint001 << myPrint2PDF > def printHDR > image 'image.jpg' 20, 1 > print 'some header text' 1,5 > ... > end > def doJob > print 'some text' 1,5 > end > end > > Here is my catch 22. I would REALLY like to call my implementation > class like this: > pr = myPrint001 :format => 'HTML' or > pr = myPrint001 :format => 'PDF' pr = MyPrint2PDF or pr = MyPrint2HTML > pr.doJob > > I have made statement 'class myPrint001 << myPrint2PDF' intentionaly > wrong and I know it does not provide the real solution, but this is how > it works for now. > > What would be the best (ruby) solution to this problem. Actually that has not much to do with Ruby, it seems your design is a little bit flawed. HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein