itsme213 schrieb:

>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" ?
>  
>
Well this should work, however,  global functions are
usually private so you should use something along the
lines of

class X
  def self.inherited(child)
    ::Object.class_eval <<-Body
      private
      def #{child.to_s.downcase}
        p "hello from #{child}"
      end
    Body
  end
  private_class_method :inherited
end

class Y < X
end
y()

/Christoph