From: nagachika00@... Date: 2017-03-13T00:57:27+00:00 Subject: [ruby-core:80085] [Ruby trunk Bug#13096] error using undef_method + refinements Issue #13096 has been updated by Tomoyuki Chikanaga. Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE to 2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE ---------------------------------------- Bug #13096: error using undef_method + refinements https://bugs.ruby-lang.org/issues/13096#change-63511 * Author: Ryan Davis * Status: Closed * Priority: Normal * Assignee: * Target version: * ruby -v: 2.3 or 2.4 * Backport: 2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE ---------------------------------------- I've got a bug report on minitest/mock that I've reduced to the following: ~~~ ruby 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 ' from bug671.rb:16:in `each' from bug671.rb:16:in `' from bug671.rb:15:in `
' ~~~ 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. -- https://bugs.ruby-lang.org/ Unsubscribe: