Ruby - Persistent local variables

For general discussion related FlowStone
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Ruby - Persistent local variables

Post by KG_is_back »

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.
Post Reply