Project

General

Profile

Actions

Bug #6374

closed

Acces to initialized class variable from included module

Added by Sega100500 (Сергей Е) about 10 years ago. Updated over 9 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
Backport:
[ruby-core:44717]

Description

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


Files

attr_module2.rb (998 Bytes) attr_module2.rb Sega100500 (Сергей Е), 04/28/2012 01:53 PM

Related issues 1 (0 open1 closed)

Related to Backport193 - Backport #6918: Fix for webrick test failures on mswin32Closed08/24/2012Actions
Actions

Also available in: Atom PDF