From: Ned Konz Date: 2002-07-10T02:33:57+09:00 Subject: Re: for ... else ... end On Tuesday 09 July 2002 10:18 am, Austin Ziegler wrote: > It might be nice to have some syntactic sugar that does something > like that: > > array.each { |e| puts e } unless array.empty then puts "Empty > array" > > (Not currently possible, AFAIK, and probably really nasty in the > interpretation of same.) > class Array def each_if_empty(blk1, &blk2) if empty? return blk1.call else each(&blk2) return self end end end [].each_if_empty(proc{ p 'is empty' }) { |item| p item } [1,2,3].each_if_empty(proc{ p 'is empty' }) { |item| p item } -- Ned Konz http://bike-nomad.com GPG key ID: BEEA7EFE