From: Michael Sullivan Date: 2001-11-20T12:23:32+09:00 Subject: [ruby-talk:25881] Re: Redefining new? I think I have this problem figured out... anyone who knows more about Ruby than my beginners level, feel free to comment. This seems to work. module Foo def new(*) # Can't do anything here yet since we don't have # have a valid object instance created yet. super # Do some stuff here... end def initialize(*) # Something by default so constructors don't complain # if the class mixing in this module doesn't have an # "initialize defined. end end class Bar include Foo def initialize # do some initialization stuff here... end end class Something < Foo def initialize(some_parm=nil) # some stuff here, but want new from the parent called # implicitly... end end Thanks, Mike On Tue, Nov 20, 2001 at 11:10:32AM +0900, Michael Sullivan wrote: > I know about how initialize works, but on page 233 of the Pickaxe book > it describes somewhat of what I want to do. > > Actually, let me clarify. I don't want the user of the class to have to > worry about overriding "initialize in my parent class. > > I actually want the code in a module which can be used asa mixin with an > include. > > Better example: > [Better example which seems to work above...] > > Another question I had come up right after I wrote this was what happens > to parameters passed to new in a case like this? > > Mike -- Michael P. Sullivan Distributed Computing Systems, LLC Cell: 516-429-2080 E-Mail: mps@discomsys.com http://www.discomsys.com/ * UNIX Systems and Database Consulting, Architecture and Management * "Failing to plan, is planning to fail... plan for the worst, hope for the best"