From: Jason Horman Date: 2001-12-09T23:37:25+09:00 Subject: [ruby-talk:28030] Re: Design question: Module or Inheritance >From ProgrammingRuby.chm: "When you include a module, Ruby creates an anonymous proxy class that references that module, and inserts that proxy as the direct superclass of the class that did the including. The proxy class contains references to the instance variables and methods of the module." This means that you can call super in a class which uses a mixin. -jason ----- Original Message ----- From: "Jim Freeze" To: "ruby-talk ML" Sent: Sunday, December 09, 2001 3:14 PM Subject: [ruby-talk:28028] Design question: Module or Inheritance > Is there any preference over the two methods > below for adding functionality to a class? > > If I needed to append some functionality to a > particular method in B, then I think Method 2 > would be required so that super could be called. > Choosing method 1 would limit this ability. > > However, Method 1 gives me the ability to inherit > from another class and still provide the functionality > of Method 2. > > > ## === METHOD 1 ==== > module B > def initialize > # ... do stuff > end > def other_funcs > # ... > end > end#module A > > class A > include B > end#class A > > or > > ## === METHOD 2 ==== > class B > def initialize > # ... do stuff > end > def other_funcs > # ... > end > end#class B > > class A < B > end#class A > > > ========================================================= > Jim Freeze > jim@freeze.org > --------------------------------------------------------- > Today is a fine day for Ruby programming. > http://www.freeze.org > ========================================================= > >