From: Damjan Rems Date: 2008-03-04T06:17:11+09:00 Subject: Re: Understanding ruby classes At the end of a day I have this solution. I have myreport001.rb which contains: class Myreport001 < MyPrint def printHDR image 'image.jpg' 20, 1 print 'some header text' 1,5 ... end def doJob print 'some text' 1,5 end end def myReport(myCustomClass, opts={}) ># source filename cFileName = myCustomClass + '.rb' ># read the source file src = File.open(cFileName) {|f| f.read} ># Replaces 'MyPrint' with MyPrint2PDF src.sub!('MyPrint','MyPrint2' + opts[:format]) ># evaluates sorce eval src ># creates new class eval myCustomClass.capitalize + '.new' end r = myReport('myreport001',:format => 'PDF') r.doReport It works. It probably has some kind of memory leak, but it works. And it is wery Rail-ish with template source file doing actualy job. And I belive it will be also very custumizeable. -- I am kind of puzzeled by the fact that this doesn't work. src.split("\n").each do |line| x+=1 eval(line) end myreport001.rb:2:in `myReport': compile error (SyntaxError) myreport001.rb:2: syntax error, unexpected $end, expecting '\n' or ';' class Myreport001 < MyPrint2PDF ^ from testsrc.rb:167:in `eval' from testsrc.rb:170:in `myReport' from testsrc.rb:167:in `each' from testsrc.rb:167:in `myReport' from testsrc.rb:174 Line 170 is: eval(line) Any ideas. And I am still open to any other suggestions. by TheR -- Posted via http://www.ruby-forum.com/.