T
Tony Tony
There is onething regarding class and scope I felt puzzled for a while.
Below is my code.
class QQ
@strange=Array.new
def report
puts @strange.class
end
end
q=QQ.new
q.report
From my understanding, instance variable should be available to every
method of a specific instance. However, if I initialize the "@strange"
array in the very begining of my class. In my method, I will derive a
NilClass. That means, there is something to do with scope. It seems that
every block would produce a local scope.
So, how can I overcome such deliemma. I want an Array that can be used
by every method in the class. Thank you in advance.
Below is my code.
class QQ
@strange=Array.new
def report
puts @strange.class
end
end
q=QQ.new
q.report
From my understanding, instance variable should be available to every
method of a specific instance. However, if I initialize the "@strange"
array in the very begining of my class. In my method, I will derive a
NilClass. That means, there is something to do with scope. It seems that
every block would produce a local scope.
So, how can I overcome such deliemma. I want an Array that can be used
by every method in the class. Thank you in advance.