Consider the following sample ruby class
class User
def hello
puts \"hello\"
end
end
now, for initialization. there are two ways
<
A local variable can be used only within the method in which it is defined (or, when the variable is defined at the top level, only outside of any method). An instance variable can be used from any method that is called on the same instance.
Here's an example where you can see the difference:
@tr = User.new
def foo
@tr.hello
end
foo
# Hello World
tr = User.new
def bar
tr.hello
end
bar
# Exception because tr is not accessible from within bar