From: shugo@... Date: 2015-12-17T22:47:23+00:00 Subject: [ruby-core:72225] [Ruby trunk - Bug #11826] After prepending a module, rewrite Hash#[] takes no effect for calls like Hash.new[:a] Issue #11826 has been updated by Shugo Maeda. Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED Shugo Maeda wrote: > It seems that redefinition check of optimized methods doesn't work properly for prepended classes. > Is the following patch correct, ko1? Committed it with a test in r53173 after checking that `make exam` succeeded. Revert it if it's wrong. ---------------------------------------- Bug #11826: After prepending a module, rewrite Hash#[] takes no effect for calls like Hash.new[:a] https://bugs.ruby-lang.org/issues/11826#change-55635 * Author: cichol tsai * Status: Closed * Priority: Normal * Assignee: Koichi Sasada * ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32] * Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED ---------------------------------------- ~~~ module M def self.prepended(clz) clz.class_eval do def [](k) p 1 end end end end module N def self.included(clz) clz.class_eval do def []=(k, v) p 2 end end end end class Hash prepend M include N end Hash.new[1] Hash.new[1]=1 ~~~ Running this example gives no output, which is expected to be '1 2'. I am using 'ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32]'. Thanks in advanced. -- https://bugs.ruby-lang.org/