From: Tristin Davis Date: 2008-06-26T09:45:59+09:00 Subject: Re: A cleaner way to pass a block or proc ------=_Part_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(interval=120) @interval = interval @notifiers = Array.new end def add_notifier(notifier=nil, &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 = true @thread = Thread.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 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 = nil, &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 > > ------=_Part_3986_1302411.1214441288671--