I wan't to set a class variable of a class from the outside(via attr_accessor), and then access it from inside one of its objects. I'm using ruby 1.9.2. This is my code:
class Service
def initialize(id)
@my_id = id
end
class << self
attr_accessor :shared_id
end
def system_id
@my_id + @@shared_id
end
end
If I set Service.shared_id = "A2", and then call Service.new("A").system_id, this doesn't return "AA2". It displays the following error:
uninitialized class variable @@shared_id in Service
The behaviour is like if I didn't set the Service.service_id. Can someone please explain why this happens?