Sporkmonger

purveyor of fabulously ambiguous eating utensils

Instance variables, class variables, and inheritance in Ruby

Posted by sporkmonger
Written February 18th, 2007

I’m seeing a lot of code that indicates to me that people don’t have a complete grasp of when to use class variables in Ruby.

Here’s a quick example script that should give people a better idea of what’s going on:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

class ExampleClass
  @variable =