------ art_3986_1302411.1214441288671
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Thanks Ben. That worked perfect. No other changes required in the class. :)
Here's the final code. Maybe someone can get some use out of it. It sends a
heartbeat (of your choosing) from your running ruby app at a given interval.
class HeartBeat
attr_accessor :interval
def initialize(interval0)
@interval nterval
@notifiers rray.new
end
def add_notifier(notifier l, &block)
if block_given?
@notifiers << block
else
@notifiers << notifier
end
end
def thump
raise ArgumentError, "You must add_notifier before you can notify" if
@notifiers.empty?
@notifiers.each {|n| n.call }
end
def start
Thread.abort_on_exception rue
@thread hread.new do
while true
thump
sleep @interval
end
end
end
def stop
@thread.terminate
end
end
On Wed, Jun 25, 2008 at 7:05 PM, Ben Bleything <ben / bleything.net> wrote:
> On Thu, Jun 26, 2008, Tristin Davis wrote:
> > It just seems really unpretty to pass that nil when I want to pass just
> the
> > block.
>
> As an alternative to Ara's suggestion:
>
> def add_notifier( notifier il, &block )
>
> You'll need to change some of your internal logic as well to deal with
> notifier being nil sometimes, but I like this better than using splats.
> Personal taste.
>
> Ben
>
>
------ art_3986_1302411.1214441288671--