I created a Test class which has an instance variable @val and which is defined inline.
class Test
@value = 10
def display
puts @value
end
end
t = Test.new
t.display
This gives no output. But if I set @val through initialize method then the code works.
@@depending on your usage of this variable likeclass Test; @@value=10; def display; puts @@value; end; endthen your proposal will work as expected. Just know that if you change this variable it will change it for all instances of this class since the variable is tied to the class itself and not an instance.