From: jweirich@... Date: 2001-11-01T01:25:44+09:00 Subject: [ruby-talk:23982] Re: Overiding a method in another module >>>>> "Mark" == Mark Hahn writes: Mark> Here is the situation that I am facing (see below). I want Mark> to add method m_2 to class C1 and make sure instances of C2 Mark> (any any other subclass of C1) respond to m_2. I cannot Mark> subclass C1 to accomplish this because I have no way to Mark> change C2 to subclass my new subclass. I cannot change the Mark> source of M1 because of the license. Even if there wasn't a Mark> license issue, isn't reusability all about using other code Mark> without changing it? Mark> module M1 << This is other person's module Mark> class C1 Mark> def m_1 Mark> ... Mark> end Mark> end Mark> class C2 < C1 Mark> ... Mark> end Mark> end Just do this in your code somewhere ... module M1 class C1 def m_2 ... end end end Ruby classes are open, so you can add new methods to them without touching the original source. -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)