Project

General

Profile

Actions

Bug #10578

closed

Allow undefining methods in refinements

Added by whitequark (whitequark *) about 10 years ago. Updated almost 10 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
[ruby-core:66741]

Description

Since refinements are locally scoped monkey patches, and it is possible and useful to undef a method globally, I think refinements should allow to undef methods as well as def them.

For example:

module NoPlus
  refine String do
    undef +
  end
end

using NoPlus
"a" + "b"

Expected behavior: undefined method `+' for "a":String
Actual behavior: undef ignored


Files

undef_in_refine.diff (992 Bytes) undef_in_refine.diff shugo (Shugo Maeda), 02/05/2015 06:42 AM

Updated by shugo (Shugo Maeda) almost 10 years ago

Peter Zotov wrote:

Since refinements are locally scoped monkey patches, and it is possible and useful to undef a method globally, I think refinements should allow to undef methods as well as def them.

The attached patch allow refinements to undef original methods.

Matz, Can I commit it?
And, is it considered a bug fix?

Actions #2

Updated by shugo (Shugo Maeda) almost 10 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Applied in changeset r49554.


  • vm_insnhelper.c (vm_call_method): stop method search when a method
    is not found in a refinement, to support undef in refinements.
    [ruby-core:66741] [Bug #10578]

Updated by shugo (Shugo Maeda) almost 10 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN

I've committed the patch because I consider this issue a bug.

However, I'm not sure whether it should be backported.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0