"itsme213" <itsme213 / hotmail.com> schrieb im Newsbeitrag
news:xEEjd.34130$tL5.5547 / fe2.texas.rr.com...
> I have defined class X. Anytime X is inherited (say, by Y), I want to
> generate a global function definition
>     def y(...) { ... }
>
> The hook I am using is
> class X
>     def self.inherited(child)
>         ...
>     end
> end
>
> What should go into the ...? Should it be
>
> Object.class_eval "def #{child.name.downcase} ... end" ?

How about

class X
    def self.inherited(child)
      Kernel.instance_eval do
        define_method(child.name.downcase) do
          puts "Method defined for #{child}"
        end
      end
    end
end

class Y < X
end

>> y
Method defined for Y
=> nil

Kind regards

    robert