From: "Thorsten Müller" Date: 2008-06-12T01:54:44+09:00 Subject: Re: each with else > makes me wanting Eric's patch for the simplified lambda syntax even > more, than we can write in pure Ruby > > module Enumerable > def each_else each_blk, else_blk=nil > return else_blk && else_blk.call if empty? > each &each_blk > end > end > > and we could call it with > > ary.each_else do | ele | puts ele end, do puts "empty" end > or > ary.each_else {|ele| puts ele }, {|| puts "empty" } > without having checked for precedence, maybe some "()" are needed ;) > > Guess that this is pretty much what OP wants, right? ;) > Yes :-) That would be something in the right direction. My first thought was to propose something like that for Rails only. But then I thought that the plain form with a "full" else would give us a cleaner syntax. Funny that you mention smalltalk. I don't know much about it, but remember to have read a discussion about it's pure oop and that you can handle even core language features like if/then/else like any other class. This would be an example where it would be handy to have it. 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...