Perhaps you can catch the callback in the method_added( ) of the Module class and check the method name and remove the added method if it does not meet your criteria. Then you can cause an error.
Not exactly, but close enough, I think.
class Class def method_added(method_name) if method_name == :bar remove_method :bar puts "#{method_name} cannot be added to #{self}" end end
source share