lib/usable/mod_extender.rb in usable-3.9.1 vs lib/usable/mod_extender.rb in usable-3.9.2
- old
+ new
@@ -16,13 +16,11 @@
end
# @description Directly include a module whose methods you want made available in +usables.available_methods+
# Gives the module a name when including so that it shows up properly in the list of ancestors
def call(target)
- unwanted.each do |method_name|
- copy.send :remove_method, method_name
- end
+ unwanted.each(&method(:remove_from_module))
if copy.name.nil?
const_name = "#{mod_name}Used"
target.send :remove_const, const_name if target.const_defined? const_name, false
target.const_set const_name, copy
end
@@ -43,8 +41,19 @@
if :constants == only
@copy.instance_methods
else
@copy.instance_methods - Array(only)
end
+ end
+
+ def remove_from_module(method_name)
+ begin
+ copy.send :remove_method, method_name
+ rescue NameError => e
+ # Expected sometimes, like it could be raised trying to remove a superclass method
+ Usable.logger.debug("#{e.class}: #{e.message}")
+ end
+ # Block access to superclass method, and prevent it from being copied to the target
+ copy.send :undef_method, method_name if copy.instance_methods.include?(method_name)
end
end
end