2009/4/24 Damjan Rems <d_rems / yahoo.com>:
> Joel VanderWerf wrote:
>> Damjan Rems wrote:
>>> end
>>> ....
>>> end
>>> run_class('my_src')
>>>
>>> Ruby is wonderful language which allows us to do this. But the
>>> substitution part is kinda ugly to me.
>>>
>>> So is there a better way of doing this?
>>
>> One idea: define A and B as modules instead of classes. Then, when you
>> load the file that defines "class MySrc < Abstract", you don't have to
>> substitute anything. Just include the module, as in:
>>
>>  ¨ÂïäõìÍïäÁ®®®» åî>>
>>  ¨Âïáæéìåîáíå ¢®òâ>>  ¨ÂÏâêåãô®ãïîóôßçåôÆéìå®âáóåîáí卿éìåîáíå©®ãáðéôáìéúå >>  ¨Âì®ãìáóóßåöáì ûéîãìõäå ÍïäÁ>
>>
>> Now, instances of cl will have all the methods of module ModA.
>
> I am trying this variation for now. And it might look like good until
> here:
>>  ¨Âì®ãìáóóßåöáì ûéîãìõäå ÍïäÁ>
> I guess my version is wrong
>  ¨Âì®ãìáóóßåöáì ¢éîãìõäå §ÄòçÒåðïòôó£ûïðôóÛºæïòíáôÝý§
Here you are creating a string only.

>  ¨ÂåðïòåöáìÆéìå®âáóåîáíå¨ãõóôïíßãìáóó©®ãáðéôáìéúå §®îå÷§ >
> because after this I get error that method found in included module is
> missing.
>
>
> 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


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/