From: "Hal E. Fulton" Date: 2001-05-11T11:06:17+09:00 Subject: [ruby-talk:14971] Module [instance] methods, append_features, etc. Hello... I have a question. Actually, several. When a module is mixed into a class via include, the module instance methods become instance methods of that class. So far, so good. (Listing 1 below.) Q1. The module methods of that module do NOT become class methods of the class. I'm not sure why that is. Q2. I found the "append_features" trick to create a class method using a module... but now the module instance methods don't show up as instance methods of the class. (Listing 2 below.) Why? Q3. OK, maybe I don't "want" to bring in both class and instance methods. Maybe I just "think I want it." I admit I don't have an application in mind; I was just experimenting. Comments? Q4. Why is it allowable to have a method definition within the append_features body but not a second one? A second one gives me a "nested method" error. I'm not understanding something pretty basic. Thanks, Hal # Listing 1 module MyMod def MyMod.aaa puts "aaa" end def bbb puts "bbb" end end class MyClass include MyMod def MyClass.ccc puts "ccc" end def ddd puts "ddd" end end x = MyClass.new x.bbb # bbb x.class.ccc # ccc x.ddd # ddd x.class.aaa # Undefined method # Listing 2 module MyMod def MyMod.append_features(someClass) def someClass.aaa puts "aaa" end end def bbb puts "bbb" end end class MyClass include MyMod def MyClass.ccc puts "ccc" end def ddd puts "ddd" end end x = MyClass.new x.class.ccc # ccc x.ddd # ddd x.class.aaa # aaa x.bbb # Undefined method