On Fri, Jun 13, 2003 at 09:36:59AM +0900, Joel VanderWerf wrote:
> >Can module2 include module2 and add features to a class from module1?
> Yes, if you cheat a little:
> 
> module M2
>   include M1
>   M1::A.instance_eval do define_method :g do "G"; end end
> end

That's cheating a lot :) The following is a little less evil:

>> module M1
>> class A; def f; "f"; end; end
>> class B; def f; "f"; end; end
>> end
=> nil
>> module M2
>>  include M1
>>  TheA = M1::A  # could as well do with A
>>  class TheA; def g; "g"; end; end  #don't want to subclass
>> end
=> nil
>> M2::A.new.g   # "g", as expected
=> "g"
>> M2::A.new.f   # works
=> "f"
>> M2::B::new.f  # "f" as expected
=> "f"
>> p M2::TheA
M1::A

But it requires M2 to know about where the classes are coming from, in
case you include several modules (but you normally should, too).

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Those who don't understand Linux are doomed to reinvent it, poorly.
	-- unidentified source