Say I have a Ruby class in my Rails project that sets an instance variable.
class Something
def self.objects
@objects ||= begin
end
end
end
Is it possible that @objectscan be installed several times? Is it possible that during one request when executing code between begin/ endabove, so that this method can be called during the second request? It really comes down to the question of how Rails server instances are deployed, I suppose.
Should I use Mutexor thread synchronization? eg:.
class Something
def self.objects
return @objects if @objects
Thread.exclusive do
@objects ||= begin
end
end
end
end
source
share