You are correct that @@variable1
is a class variable and @variable2
is an instance variable of the class. The two snippets are not equivalent because @@variable2
(only defined in snippet two) is also a class variable.
(Note: I assume that your irb output has a typo and that it should have included @variable2
and only after invoking MyClass.my_method
.)