From: chiether+ruby@... Date: 2014-03-06T18:42:57+00:00 Subject: [ruby-core:61336] [ruby-trunk - Bug #9603] [Open] unusual reference class-variable with cloned class. Issue #9603 has been reported by Norikaz Ishii. ---------------------------------------- Bug #9603: unusual reference class-variable with cloned class. https://bugs.ruby-lang.org/issues/9603 * Author: Norikaz Ishii * Status: Open * Priority: Normal * Assignee: * Category: * Target version: * ruby -v: ruby 2.1.2p80 (2014-03-01 revision 45231) [x86_64-linux] * Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- description ----------- Maybe panic reference to class-variable in cloned class. Not really sure about bug. But hang over my head. I think minor irritant it which whether problem or not. because impractical code. sample code ----------- class A @@value = 1 def self.make_instance @@value = 2 new end def data @@value end end puts A.make_instance.data # => 2 -- collect!! class B def self.make_clone C.clone end class C @@value = 1 def self.make_instance @@value = 2 new end def data @@value end end end [pattern 1] puts B.make_clone.make_instance.data # => 1 -- wrong puts B.make_clone.make_instance.data # => 2 -- collect [pattern 2] puts B::C.make_instance.data # => 2 -- collect puts B.make_clone.make_instance.data # => 2 -- collect expected -------- [pattern 1] 2 2 [pattern 2] 2 2 actual ------ [pattern 1] 1 2 [pattern 2] 2 2 noticed ------- ruby-1.8.6-p420, ruby-1.9.3-p545, ruby 2.1.2p80 all problem. but codepad(1.8.6) is looking for expected. http://codepad.org/1VPpyCvy -- http://bugs.ruby-lang.org/