Module#initialize_copy does not clean the tables

Issue #9813 has been updated by Usaku NAKAMURA.

backported into ruby_2_0_0 at r46519.


Bug #9813: Module#initialize_copy does not clean the tables
https://bugs.ruby-lang.org/issues/9813#change-47345

  • Author: Nobuyoshi N.
  • Status: Closed
  • Priority: Normal
  • Assignee:
  • Category: core
  • Target version:
  • ruby -v: r45873
  • Backport: 2.0.0: REQUIRED, 2.1: DONE

Module#initialize_copyで定数やインスタンス変数を持たないModuleをコピーしても、元の定数やインスタンス変数が残っています。

m = Module.new do
  def x
  end
  const_set(:X, 1)
  @x = 2
end
p m.instance_methods, m.instance_variables, m.constants
#=> [:x]
#=> [:@x]
#=> [:X]
m.module_eval do
  initialize_copy(Module.new)
end
p m.instance_methods, m.instance_variables, m.constants
#=> []
#=> [:@x]
#=> [:X]

1.8でinitialize_copyが導入された当初からあるバグのようです。

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs