Bug #10578
closedAllow undefining methods in refinements
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
Updated by shugo (Shugo Maeda) over 9 years ago
- File undef_in_refine.diff undef_in_refine.diff added
- Status changed from Open to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
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?
Updated by shugo (Shugo Maeda) over 9 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) over 9 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.