I wanted to write a small library called "Deprecate-It" and reused the method_added callback. But now I noticed that this callback does not start when the module is turned on.
Are there any callbacks or workarounds to get information about the Foobar class when some information is included?
A small demonstration to demonstrate:
module InvisibleMethod
def invisible
"You won't get a callback from me"
end
end
class Foobar
def self.method_added(m)
puts "InstanceMethod: '#{m}' added to '#{self}'"
end
def visible
"You will get a callback from me"
end
include InvisibleMethod
end
[:invisible, :visible, :wont_exist].each do |meth|
puts "#{meth}: #{Foobar.public_method_defined? meth}"
end
What is the result:
InstanceMethod: 'visible' added to 'Foobar'
invisible: true
visible: true
wont_exist: false
Additional Information:
I really need to use a hook, for example method_added.
ActiveModel adds public_instance_methods to the class at runtime, although anonymous modules.
source
share