Without @ it is discarded when the method in which it is executed is executed.
class Foo def initialize @bing = 123 zing = 456 end def get_bing @bing end def get_zing zing end end foo = Foo.new foo.get_bing
This shows that the @bing instance @bing saved with this instance. This value is available in any method in this instance.
But the local zing variable zing not saved (in most cases), and as soon as this method is executed, any local variables are discarded and are no longer available. When get_zing run, it searches for a local variable or method named zing and does not find it, because zing has left the initialize long ago.
source share