Functions and arrays (ruby)

Soldato
Joined
24 Nov 2002
Posts
16,378
Location
38.744281°N 104.846806°W
Is it possible to access a function defined/filled array from outside the function?

e.g.

Code:
def foo()
 arr = [blah blah blah]
end

foo()

puts arr
 
JonB said:
I'm not really au fait with ruby, but to do this in another language you would normally have to make the arr variable global or return it as a public variable inside the function.
I've read that to do the former was bad so was looking for an alternative....

Referring it as a public inside isn't really an option so I've settled for a global var for now before I rewrite the blasted thing.
 
The problem is my function does a few things so I can't call it as above.

I'll just have to use global arrays ... or rewrite.
 
Back
Top Bottom