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)
    end while yield and (times -= 1) != 0

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.

One response

  1. What about this sort of syntax, and using the ruby throw/catch capabilties:

    every(1.minute, :until => :done) do
      puts "a minute passed"
      throw :done if some_condition

    implementation is left up to the reader :)