Hello --

On Tue, 20 Nov 2001, Michael Sullivan wrote:

> module Foo
>
>    def new(*)
>       super
>    end
>
>    def initialize(*)
>    end
>
> end
>
>
> class Bar
>
>    include Foo

In the immortal words of the woman who sang that song with Meat Loaf,
"Stop right there!"  :-)

As soon as you create class Bar, a *class* method called Bar.new is
created.  In your Foo module, you have created an *instance* method
called new.  So by including Foo, you've given a new method to
*instances* of Bar, but not to Bar itself.

However, class methods are really just instance methods of classes:

  class C
    def C.thing
    end
  end

  class << C             # open up C's singleton superclass
    p instance_methods
  end

  # =>  ["thing"]

In other words: class methods of C are instance methods of class << C.

Therefore: what you want is for your Foo#new method to be an instance
method of.... not Bar, but class << Bar.

  class Bar
    class << self    # open up Bar's singleton superclass
      include Foo    # and add to it
    end
>
>    def initialize
>    end

Whoops, I erased your comments, but there was something about
constructors complaining about lack of an initialize method....  I'm
not sure what you meant.

I'm still not clear on why you want to do all this :-)  but anyway,
here's a little testbed for it:

  module Foo
    def new
      super
      puts "Here I am"
    end
  end

  class Bar
    class << self
      include Foo
    end
  end

  class Something < Bar
  end

  Something.new   # =>  Here I am


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav