module Agilibox::Monkey extend ActiveSupport::Concern class_methods do def prepend_instances(&) m = Module.new(&) send(:prepend, m) end def prepend_class(&) m = Module.new(&) singleton_class.send(:prepend, m) end def prepend_instance_method(name, &) check_instance_method_exist!(name) m = Module.new m.send(:define_method, name, &) send(:prepend, m) end def prepend_class_method(name, &) check_class_method_exist!(name) m = Module.new m.send(:define_method, name, &) singleton_class.send(:prepend, m) end def check_instance_method_exist!(name) raise "instance method `#{name}` does not exist" unless instance_methods.include?(name) end def check_class_method_exist!(name) raise "class method `#{name}` does not exist" unless methods.include?(name) end end end