Project

General

Profile

Bug #14374

`for` does not splat elements

Added by nobu (Nobuyoshi Nakada) over 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:84931]

Description

In general, it is said that for statement and each method call are similar, except for the scope of loop variables.
I found another difference, since 1.9.

a = [Struct.new(:to_ary).new([1, 2])]
a.each {|i, j| p [i, j]} #=> [1, 2]
for i, j in a; p [i, j]; end #=> [#<struct to_ary=[1, 2]>, nil]


In 1.8, the latter result equals the former.
Is this intentional?

Also available in: Atom PDF