---------------------------------------------------------- Object#extend
     obj.extend(module, ...)    => obj
------------------------------------------------------------------------
     Adds to _obj_ the instance methods from each module given as a
     parameter.

        module Mod
          def hello
            "Hello from Mod.\n"
          end
        end

        class Klass
          def hello
            "Hello from Klass.\n"
          end
        end

        k = Klass.new
        k.hello         #=> "Hello from Klass.\n"
        k.extend(Mod)   #=> #<Klass:0x401b3bc8>
        k.hello         #=> "Hello from Mod.\n"

Regards

Maria

On 2008-03-06 01:19:14 +0100, Chirag Patel <patelc75 / yahoo.com> said:

> I would like to create a new superclass 'Super' for an existing class
> 'Sub'
> 
> class Sub
>   def new
>      #do something second
>   end
> end
> 
> class Super < Sub
>   def new
>      #do something first
>   end
> end
> 
> Is it possible create this new Super class so that Super::new is called
> every time Sub:new is called without modifying Sub?
> 
> The is because Sub already exists and I don't want to tamper the code.
> Basically I have a bunch of existing classes that I want to inherit from
> 'Super' so that I can include some error handling in 'Super'. Is there
> another better way to accomplish this without modifying the existing
> subclasses?
> 
> Thanks!
> Chirag