On 10/29/07, Pit Capitain <pit.capitain / gmail.com> wrote:

> Hi Brian, sorry for the late reply. Here's something with a simpler
> calling syntax:
>
>   module SkipN
>     @callers = Hash.new(0)
>     def self.skip(n = 1, key = caller.first)
>       yield if (@callers[key] += 1) > n
>     end
>     def self.skip_first
>       skip(1, caller.first) { yield }
>     end
>   end

Bravo!

> Note that this only works in simple cases. For example it's not thread-safe.

It also leaks memory since the @callers class instance variable never
has the keys deleted.

But cool nonetheless.


-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/