Would an array do what you want?
def act(data)
# Creates the array 'd'
# d[0], d[1] and so on is available now
end
def use1()
#use some of the d's ( it can be d[2], d[7] )
end
I think that you do have to use the instance '@d'. 'd' Is local to the
current method (if I understand Ruby scope correctly).
Hope that helps.
Daniel Carrera
Graduate Teaching Assistant. Math Dept.
University of Maryland. (301) 405-5137
On Sun, 29 Dec 2002, RubyQ wrote:
> I run into the following situation: I have to pre-process some data and
> then use varaibles to represent these processed data. I also want to
> use these variables in many places but I do not want to turn all of them
> into class instance variables. (@variable, that is) and I don't want to
> pass them as parameters for the method ( so I could use anything I want
> without changing the method declaration)
>
> What are the alternatives?
>
> Thanks.
>
> RubyQ.
>
> Example:
>
> class Something
>
> def initialize(v1, v2, data)
> # blah, blah, blah
> end
>
> def act(data)
> #preprocess the data
> #d1, d2, d3 and so on is available now
>
> end
>
> def use1()
> #use some of the d's ( it can be d2, d7 )
> end
>
> def use2()
> #use some of the d's (it can be d1, d4 )
>
> end
>
> def use3()
> # and so on....
> end
>
>
> end
>
>