Why can't I just do this to override M1::C1::meth in M2?

module M1
  class C1
    def meth
      p 'M1.meth'
    end
  end
end
include M1

module M2
  class M1::C1      <=== gives syntax error
    def meth
      p 'M2.meth'
    end
  end
end
include M2

C1.new.meth   => M2.meth

-----Original Message-----
From: Mark Hahn [mailto:mchahn / facelink.com]
Sent: Tuesday, October 30, 2001 12:47 PM
To: ruby-talk ML
Subject: [ruby-talk:23866] Overiding a method in another module


I want to write a module that overrides a method in another module.  I have
figured out a way to do this, but my technique seems awfully complicated.
Is there an easier way to do this?

This is the existing module that I want to override:

module M1
  class C1
    def meth
      p 'M1.meth'
    end
  end
end
include M1

This is my new module that overides the old method "meth".

module M2
  class << C1
    alias :old_new :new
    def new(*args)
      newInstance = old_new *args
        class << newInstance
          alias :old_meth :meth
          def meth(*a)
            p 'M2.meth'
          end
        end
      return newInstance
    end
  end
end

include M2

C1.new.meth  => M2.meth