Re: Ruby - Persistent local variables
Posted: Fri Sep 26, 2014 4:27 pm
Perfect Human Interface wrote:Can you give me an example of that in syntax?
For example say I want to do this (just random):Code: Select all
for i in 0...(@Array.length-1)
if @Array[i] == @input
@Array[i] = 0;
end
end
and I want @Array to be persistent.
the array should be persistent with that code. I recommend putting this in the beginning of the code, so the array is initialized on startup:
Code: Select all
def init
@Array=[0] #array with only one element. even empty array might do the trick
end
Also look at the savestate and loadstate methods in manual.