From: "matz (Yukihiro Matsumoto)" Date: 2012-04-10T18:47:13+09:00 Subject: [ruby-core:44260] [ruby-trunk - Bug #4307][Rejected] include fails after undef_method Issue #4307 has been updated by matz (Yukihiro Matsumoto). Status changed from Assigned to Rejected lsegal's comment is right. undef_methods defies the definition of upper classes, include mixed modules. So, this is expected behavior. Matz. ---------------------------------------- Bug #4307: include fails after undef_method https://bugs.ruby-lang.org/issues/4307#change-25796 Author: adrianomitre (Adriano Mitre) Status: Rejected Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: 1.9.2 ruby -v: ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux] =begin After using #undef_method on a method "inherited" from a mixin, reincluding the mixin should redefine it, but that is not what happens. Please take a look at this short IRB transcript (source attached): >> module Foo; def foo; 42; end; end => nil >> Array.class_eval { include Foo } => Array >> [1].foo => 42 >> Array.class_eval { Foo.instance_methods.each {|m| self.class_eval { undef_method m } } } => [:foo] >> [1].foo NoMethodError: undefined method `foo' for [1]:Array from (irb):5 from /home/adriano/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `
' >> Array.class_eval { include Foo } => Array >> [1].foo NoMethodError: undefined method `foo' for [1]:Array from (irb):7 from /home/adriano/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `
' The last command should just return 42, instead of raising a NoMethodError exception. Note that this also applies to the following Ruby implementations: * ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux] * rbx-1.2.0-20101221 [ ] * jruby-1.5.6 [ amd64-java Thus, it may be a language specification gap, not just an implementation bug. =end -- http://bugs.ruby-lang.org/