From: Martin DeMello Date: 2008-06-12T02:19:29+09:00 Subject: Re: each with else On Wed, Jun 11, 2008 at 9:54 AM, Thorsten Müller wrote: > > hmmmm, maybe the RCR should be even more comprehensive and > request for a completely new language construct that would allow > to built new core commands, based on multiple blocks. > Not only if/then, but case/when also. > > But that's too much for now, a new each would be enough... More simply, you can define an Object#if_empty class Object def if_empty yield if self.empty? end end a.each {|x| do something}.if_empty { do something else } this relies on the fact that obj#each returns obj. martin