I would like to do some magic in the moment instance and class methods are added to some class. Therefore I tried the following:
module Magic
def self.incl
you are looking for singleton_method_added:
module Magic
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def method_added(name)
puts "instance method '#{name}' added"
end
def singleton_method_added(name)
puts "class method '#{name}' added"
end
end
end
class Foo
include Magic
def bla
end
def blubb
end
def self.foobar
end
end
Output:
instance method 'bla' added
instance method 'blubb' added
class method 'foobar' added
Enjoy!