On Tue, Mar 5, 2013 at 7:38 PM, Hans Mackowiak <[email protected]> wrote:
> Robert Klemme wrote in post #1100233:
>> On Tue, Mar 5, 2013 at 7:23 PM,  <[email protected]> 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/

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to