From: Alex Young Date: 2007-04-27T16:59:43+09:00 Subject: Re: Timer Class Hussain wrote: > Hai Dude > > I want to write one class that class should act as a Timer > On that class , i will check the database every second for database > field called Diaplay_time ,if the current system time matched with > database Display_Time field data then i will show the message in > console,That class should terminate only when i press "Ctrl+C" key > otherwise that wont stop You can write a very simple while loop for this: while true do start_time = Time.now #do database stuff total_time = Time.now - start_time sleep(1.0 - total_time) # ignoring the possibility of total_time > 1 end Alternatively, to make it more Rubyish, use a block or two (untested): def time_block start_time = Time.now yield return Time.now - start_time end def repeat_every(seconds) while true do sleep( seconds - time_block { yield } ) # again ignoring time > seconds end end Use it like this: repeat_every(1.0) do # do database stuff end -- Alex