From: David Bailey Date: 2006-03-29T03:37:09+09:00 Subject: Re: Callback For A Timer Event To Display Widget in Ruby/Tk Hidetoshi NAGAI wrote: > From: David Bailey > Subject: Re: Callback For A Timer Event To Display Widget in Ruby/Tk > Date: Tue, 28 Mar 2006 20:17:14 +0900 > Message-ID: >> I have two quick questions: will my creation of all those Time.new >> objects (two per second) cause me to run out of resources if I do it for >> a long time? > > Probably, if you don't keep any references for those Time objects, > GC will release the resources of those objects. > >> Secondly, while this 'elapsed time' code works: >> >> "Elapsed is #{(Time.at(Time.new.to_i - (oldTime.to_i - >> 18000))).strftime("%X")}" >> >> I have a sneaky feeling that it is not the best (Ruby?) way. Is it way >> too resource wasteful, and if so, is there a more "Ruby" way? > > I think the following returns the same result as yours. > ------------------------------------------------------------- > basetime = (Time.now - 18000).to_f # instead of "oldTime" > > "Elapsed is #{(Time.now - basetime).strftime("%X")}" H.N., Yes, it gives the same results. And it is much cleaner. My method was a "Brute Force Coding" technique, because I do not understand the Time class' methods fully. I shall go back and study it more. I'm having trouble placing my 'current time' and 'elapsed time' displays (TkLabels) where I want them. I'm now studying the Ruby/Tk geometry manager indirectly via a Perl/Tk book. I haven't mastered it enough to ask any intelligent questions yet, though. If I have problems all day, I may ask you a question tomorrow. In any case, again, thank you for your gracious assistance. D.B. -- Posted via http://www.ruby-forum.com/.