in an instance method, if i didn’t use @n but used n, the program still
runs…
and it is not changing the global n… so what is it changing?
Example:
n = 10
class Foo
def initialize(i)
@n = i
end
def change()
puts
puts “Inside of change!!!”
n = 111111 # intentionally not using @n
end
def print_it
puts
p “Printing Object”
p @n
end
end
foo = Foo.new(3)
foo.print_it
foo.change
foo.print_it
puts
p “Global var”
p n
-------- output
C:\rails\depot>ruby test_class01.rb
“Printing Object”
3
Inside of change!!!
“Printing Object”
3
“Global var”
10