Project

General

Profile

Actions

Bug #14671

closed

Refining Module#refine itself introduces strange state

Added by shyouhei (Shyouhei Urabe) almost 6 years ago. Updated almost 4 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-04-09 trunk 63122) [x86_64-darwin15]
[ruby-core:86487]
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) almost 4 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

Also available in: Atom PDF

Like0
Like0