From: John Crichton Date: 2010-07-13T03:45:36+09:00 Subject: while loop end action I am trying to write a script that when certain circumstances arise it creates an object instance that adds some info to a temporary array for a given time. When the given time is up I would like to perform a couple actions and print the array. After that the array and object instance will no longer be needed, so I would like to ensure the obj is freed from memory. I am pretty new to coding and to Ruby, what is the best way to accomplish this. I thought it would be a while loop but I am confused as to how to perform an action once my counter or time has reached it's end. For example, where can I put the ending action? class Blah def initialize @myarray = Array.new @init_time = Time.now.to_f @twomin = @init_time + 120 end def add_to_array(x) while Time.now.to_f < @twomin @myarray << x end #pp @myarray.inspect end end Since the while loop has a definite end. Does this end the object's instance, I suspect no and I need to put some die statement in there or delete the object from outside the object? If I do an if/else loop than it will continue to run I suspect too. if Time.now.to_f < @twomin @myarray << x else pp @myarray.inspect end How can I properly run some actions or a method after my counter/time has reached it's end and then delete the obj instance? Thanks -- Posted via http://www.ruby-forum.com/.