Callback for classes defined inside a Module
问题 Ruby already has several built-in callbacks. Is there a callback for such case? Kinda like method_added, but for classes (or constants) inside a module, instead of instance methods inside a class. 回答1: As far as I know, there is nothing exactly like what you're describing. However, here's how you could create your own, using Class::inherited . module MyModule def self.class_added(klass) # ... handle it end class ::Class alias_method :old_inherited, :inherited def inherited(subclass) MyModule