Although I have declared the FooFactory class as "Singleton", its class variable @@foo gets instantiated every time. Why is this so?
The main singleton class:
require 'singleton'
class FooFactory
include Singleton
@@foo = nil
def get_foo
print @@foo.nil?.to_s
@@foo ||= "I am a string"
return @@foo
end
end
The controller code:
class PagesController < ApplicationController
def home
@foo = FooFactory.instance.get_foo
end
end
The view code :
<%= @foo %>
I expect that the print method in the FooFactory should return false after the FooFactory has been instantiated for the first time. But the console keeps on printing true everytime I refresh the pages/home view.