Static and class variable?

In rails, What is the difference between static and class variable? Is
it the same or different?


It’s different

class variables are variables of the class
Their value is shared by all objects

Class Something
@@class_variable = 0

def do_something
@@class_variable +=1

foo =
bar =

After that code @@class_variable will be 2
It behaves like a static class variable in C++

There are no static variables on a function level like in C++ as far
as I know
You can use normal class attributes or class variables instead
(depending if you want them per object or not)

Here is some longer discussion on the topic:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs