Project

General

Profile

Actions

Bug #11826

closed

After prepending a module, rewrite Hash#[] takes no effect for calls like Hash.new[:a]

Added by cichol (Renxiang Cai) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32]
[ruby-core:72186]

Description

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0