Shared memory in RoR

It appears that there is no official solution for static variables in the rails application since the @@ variables are reset for every thread that is initiated for a response.

To solve this, in a not so elegant manner, I’ve employed the common memory accessible on the Tread.main
if Thread.main[:counter] == nil
Thread.main[:
counter]=0
end
counter= Thread.main[:counter] += 1

(originally from giladmanor.com)

Good Luck

This entry was posted in Software Development. Bookmark the permalink.

Leave a Reply