module PrependDependenciesCheckable def check_prepend_dependencies(target, dependencies) order = Array(dependencies[:before]) + [target] + Array(dependencies[:after]) self.class.ancestors.reverse.each { |cls| order.shift if cls == order.first } order.empty? end def check_prepend_dependencies!(target, dependencies) unless check_prepend_dependencies(target, dependencies) raise "Invalid prepend dependencies. target:#{target} ancestors:#{self.class.ancestors} dependencies:#{dependencies}" end end end class Object include PrependDependenciesCheckable end