Actions
Bug #14671
closedRefining Module#refine itself introduces strange state
Bug #14671:
Refining Module#refine itself introduces strange state
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-04-09 trunk 63122) [x86_64-darwin15]
Tags:
Description
using Module.new {
refine Module do
def refine *;
puts self
end
public :refine
end
}
Object.refine # => NoMethodError
It is possible to refine Module#refine, but there seems to be no way to call it.
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Status changed from Open to Rejected
This is because Class undefs refine, and the refinement for Module is after the lookup chain for Class. Your code works fine if you call refine on a Module and not a Class, or if you remove the undef from Class. Ruby does not support directly removing an undef through remove_method, but you can override the method and remove the overridden method. This code:
using Module.new {
refine Module do
def refine *;
puts self
end
public :refine
end
}
Enumerable.refine
Class.define_method(:refine){}
Class.remove_method(:refine)
Object.refine
prints:
Enumerable
Object
Your code also works if you refine Class instead of Module.
Actions