Actions
Bug #13096
closederror using undef_method + refinements
Description
I've got a bug report on minitest/mock that I've reduced to the following:
class Object
def to_query # remove this, works fine
end
end
Object.prepend Module.new # remove this, works fine
module ObjectExtensions
refine ::Object do
def to_query # remove this, works fine
end
end
end
class Mock
instance_methods.each do |m|
next if m =~ /object_id|__send__/
undef_method m
end
end
giving me the error:
bug671.rb:18:in `undef_method': undefined method `to_query' for class `Mock' (NameError)
from bug671.rb:18:in `block in <class:Mock>'
from bug671.rb:16:in `each'
from bug671.rb:16:in `<class:Mock>'
from bug671.rb:15:in `<main>'
This code comes from activesupport via regular requires, so this is a real problem for me.
Looks like the culprit might be here:
https://github.com/ruby/ruby/blob/v2_4_0/vm_method.c#L1187
I'd expect to be able to undef anything that comes back from instance_methods
regardless of whether there is a refinement in place or not.
Additionally, the error message is just plain wrong. The method is most certainly defined (twice!) and should be improved.
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
- Status changed from Open to Closed
Applied in changeset r57362.
vm_method.c: resolve refined method to undef
- vm_method.c (rb_undef): resolve the method entry which refines a
prepended method entry. [ruby-core:78944] [Bug #13096]
Updated by naruse (Yui NARUSE) over 7 years ago
- Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE
ruby_2_4 r57862 merged revision(s) 57362.
Updated by nagachika (Tomoyuki Chikanaga) over 7 years ago
- Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE to 2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE
Updated by usa (Usaku NAKAMURA) over 7 years ago
- Backport changed from 2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE
Updated by usa (Usaku NAKAMURA) over 7 years ago
- Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: DONE, 2.3: REQUIRED, 2.4: DONE
ruby_2_2 r58126 merged revision(s) 57362.
Updated by nagachika (Tomoyuki Chikanaga) over 7 years ago
- Backport changed from 2.2: DONE, 2.3: REQUIRED, 2.4: DONE to 2.2: DONE, 2.3: DONE, 2.4: DONE
ruby_2_3 r58174 merged revision(s) 57362.
Actions
Like0
Like0Like0Like0Like0Like0Like0