Project

General

Profile

Actions

Bug #10765

closed

Module#remove_method remove refined method entry.

Added by hanachin (Seiei Miyagi) over 9 years ago. Updated about 9 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-01-21 trunk 49326) [x86_64-darwin14]
[ruby-core:67722]

Description

Module#remove_method should raise a NameError
if method is not defined in refined class, such as undef.
But if method is defined in refined class, Module#remove_method should keep refined method and remove original method.

I confirmed by following examples in ruby-trunk, 2.2.0, 2.1.5, 2.0.0-p598

class C
  def foo
    "C#foo"
  end
end

module RefinementBug
  refine C do
    def foo
      "RefinementBug#foo"
    end
  end
end

using RefinementBug

class C
  remove_method :foo
end

puts C.new.foo

# expected:
#   RefinementBug#foo
#
# actual:
#   bug.rb:21:in `<main>': undefined method `foo' for #<C:0x007f9e5c087b48> (NoMethodError)
class C
end

module RefinementBug
  refine C do
    def foo
    end
  end
end

using RefinementBug

class C
  remove_method :foo
end

# expected:
#   bug2.rb:14:in `remove_method': method `foo' not defined in C (NameError)
#   from bug2.rb:14:in `<class:C>'
#   from bug2.rb:13:in `<main>'
#
# actual:
#   # => nothing raised.

Files

bug2.rb (327 Bytes) bug2.rb hanachin (Seiei Miyagi), 01/21/2015 01:46 PM
bug.rb (342 Bytes) bug.rb hanachin (Seiei Miyagi), 01/21/2015 01:46 PM
0001-vm_method.c-fix-remove-refined-method.patch (2.68 KB) 0001-vm_method.c-fix-remove-refined-method.patch hanachin (Seiei Miyagi), 01/21/2015 01:50 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #10826: Refinements make instance_methods(false) return methods of superclassesClosedshugo (Shugo Maeda)02/04/2015Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0