From: Robert Klemme Date: 2003-03-13T20:18:23+09:00 Subject: Re: next iteration within a block "Wojciech Kaczmarek" schrieb im Newsbeitrag news:b4p7bt.114.1@schatten.at.transilvania... > 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"? > In a real code, when I don't want to make the content of a block a > multibranched if statement (or something similar), I use something > like that: 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 or ['bar','quux'].select{|e| e != 'bar' }.map{'foo'} Regards robert