snax

a little baby ruby poem

A little Ruby poem, engendered during a discussion of how to run a block at fixed time intervals (like cron).

gem install activepoem

class Fixnum
  def minutely_do(times = 0)
    begin
      sleep(self*60)
    end while yield and (times -= 1) != 0
  end
end

some literature

Now we can write:

1.minutely_do { puts "a minute!" or true }

And that totally rhymes.

We would need to put the call in its own thread if we wanted to use this in real life, in most cases.