Heey I am new to Ruby. I need to create a factory method, which will return me an object of a class. Using that object I should be able to access the variables of the class. I have written the following code, but I surely have miss something.
class Super
@@super_temp = 1
def Super.get_instance(world)
platform = world
if @@instance == nil
if platform==1
@@instance = BaseA.new
else
@@instance = BaseB.new
end
end
return @@instance
end
end
class BaseA < Super
@@base_temp = 2
end
class BaseB < Super
@@base_temp = 3
end
class Demo
def Demo.call_demo
obj = Super.get_instance(0)
puts "---------temp is #{obj.base_temp}"
end
end
Demo.call_demo
I need to retrieve the value of base_temp in class Demo.