# Class level variables in Mongrel

**URL:** <https://www.ruby-forum.com/t/class-level-variables-in-mongrel/110082>\
**Category:** Rails\
**Created:** [July 22, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/class-level-variables-in-mongrel/110082 "2007-07-22T20:52:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/82dd89/32.png) [@kris](https://www.ruby-forum.com/u/kris)\
**Post date:** [July 22, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/class-level-variables-in-mongrel/110082/1 "2007-07-22T20:52:47Z")

</div>

I’m trying to use a class level variable @@count as a counter between  
requests to the server. So for example I initialize it @@count = 0 at  
the top of the class and in a method I have @@count = @@count+1. It  
seems though that @@count is begin reinitialized back to 0 each time the  
controller is called. Is there something that I’m missing here? I’m  
running under mongrel on Linux.

---

<div class="post-metadata">

**Author:** ![kris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/82dd89/32.png) [@kris](https://www.ruby-forum.com/u/kris)\
**Post date:** [July 22, 2007, 9:05pm UTC](https://www.ruby-forum.com/t/class-level-variables-in-mongrel/110082/2 "2007-07-22T21:05:01Z")

</div>

Kris Kohlstedt wrote:

> I’m trying to use a class level variable @@count as a counter between  
> requests to the server. So for example I initialize it @@count = 0 at  
> the top of the class and in a method I have @@count = @@count+1. It  
> seems though that @@count is begin reinitialized back to 0 each time the  
> controller is called. Is there something that I’m missing here? I’m  
> running under mongrel on Linux.

Well for every request to the server you would get a new class variable  
🙂
