From: "nobu (Nobuyoshi Nakada)" Date: 2012-04-28T19:40:03+09:00 Subject: [ruby-core:44728] [ruby-trunk - Bug #6374] Acces to initialized class variable from included module Issue #6374 has been updated by nobu (Nobuyoshi Nakada). It's a spec. Class variables belong to the static scope of classes, as well as constants. ---------------------------------------- Bug #6374: Acces to initialized class variable from included module https://bugs.ruby-lang.org/issues/6374#change-26289 Author: Sega100500 (������������ ��������) Status: Open Priority: Normal Assignee: Category: Target version: 1.9.3 ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux] # Description of bug (?) below in comments of code # May by it is not a bug, but feature ? module Variables def print_var print "In module #{self.class.name}: #{@variable}\n" end def print_class_var print "In module class-variable #{self.class.name}: #{@@class_variable}\n" end def set_variables(var, cvar) @variable = var @@class_variable = cvar end end class A include Variables def initialize(var, cvar) @variable = var @@class_variable = cvar end def print_variables print "variables: #{@variable}, #{@@class_variable}\n" end def self.print_class_a_variables print "Class '#{self.class.name}' variable: #{@@class_variable}\n" end end class B < A end a = A.new(123, 456) A.print_class_a_variables B.print_class_a_variables a.print_variables a.print_var a.print_class_var # fail: :8:in `print_class_var': uninitialized class variable @@class_variable in Variables (NameError) # Why? I set '@@class_variable` in 'initialize' a.set_variables(12, 33) # Once again set '@@class_variavle' a.print_class_var # But this method is tested -- http://bugs.ruby-lang.org/