From: Robert Klemme Date: 2013-03-06T03:53:33+09:00 Subject: Re: How `next` works in ruby with `unless` ? On Tue, Mar 5, 2013 at 7:38 PM, Hans Mackowiak wrote: > Robert Klemme wrote in post #1100233: >> On Tue, Mar 5, 2013 at 7:23 PM, wrote: >>>> executed. Why does next not skip this statement ? >> Probably because arguments are always evaluated before the "method" >> they are handed over to. >> >>> Nobody writes code like this, so why care. >> >> I wasn't even aware that next accepts an argument - funnily it won't >> accept two (syntax error). > hm it does: > > [1,2,3,4].map {|d| next d,4,5;p "is not printed" } > #=> [[1, 4, 5], [2, 4, 5], [3, 4, 5], [4, 4, 5]] Oh, I tested only with brackets. Here's the whole story $ ruby -ce 'f { next }' Syntax OK $ ruby -ce 'f { next 1 }' Syntax OK $ ruby -ce 'f { next 1, 2 }' Syntax OK $ ruby -ce 'f { next 1, 2, 3 }' Syntax OK $ ruby -ce 'f { next(1) }' Syntax OK $ ruby -ce 'f { next(1, 2) }' -e:1: syntax error, unexpected ',', expecting ')' f { next(1, 2) } ^ It's getting weirder - especially since the value(s) passed to next are not used for anything as far as I can see. And it wouldn't make sense, would it? I mean, next is different from break which can be used to return a value from an iteration. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/