I have a class like so:
class MyNumber
@@number = nil
unless @@number
@@number = rand(10)
end
def number
@@number
end
end
When I subsequently call the number method on this class the number keeps changing. I just want to set this number once and have it remain the same for the entire life of the class. How can I achieve this.
In java parlance, I am trying to have a static variable and static method for this class.
It was being caused by rails auto unloading/reloading. There is a workaround that lets the class persist across requests.
In my environment.rb I had to add this