Robert Klemme wrote:

>> How to write the line correct?
> 
> This should work:
> 
> cl.class_eval "include 'DrgReports#{opts[:format]}'"
> 
> But again, inclusion - which is a special form of inheritance - does
> not seem the proper technique here.
> 
> Kind regards
> 
> robert

Thanks this works now. I had to leave out single quotes.

def run_report(source_file, opts={}, default_opts={})
  opts[:format] ||= 'HTML'
  load source_file + '.rb'
  cl = Object.const_get File.basename(source_file).capitalize
  cl.class_eval "include DrgReports#{opts[:format]}"
  report = cl.class_eval 'new'

  report.set_options(default_opts)
  report.set_options(opts)
  report.create
  report.do_report
  report.close
end

It looks nicer and I understand a piece of Ruby a little more.

I will try to study delegation this weekend.


by
TheR
-- 
Posted via http://www.ruby-forum.com/.