Robert Klemme <bob.news / gmx.net> wrote:
> 
>> What is the most short/elegant way of ending the current iteration within a
>> block? My first thought was that `next' will break the iteration and last
>> evaluated expr will be returned to the caller, but surprisingly `nil' is
>> returned this way, so we have (Ruby 1.6.8):
>> ['bar','quux'].map {'foo'; next; 42}
>> => [nil, nil]
> 
> What about 
> ['bar','quux'].map {'foo'}
> 
> Why do you need the "next"?

I can assure you I don't need it in the above example :->

> I assume you want to go trough the array, map values and omit some of
> them.  You can do
> 
> ['bar','quux'].map {|e| e == 'bar' ? nil : 'foo'}.compact
> ['bar','quux'].select{|e| e != 'bar' }.map{'foo'}

That's good, but let's imagine the selection predicate as a
fatty-several-times-nested statement -- it'd be convenient to leave block
with a proper value sooner in some simpler cases.

Anyway, the syntax I dream of is avalilable in 1.7.

-- 
- How can you make anyone into a star? 
- I dunno. I suppose you compress them right up small 
  and they burst into this mass of flaming hydrogen?