Project

General

Profile

Actions

Bug #14374

closed

`for` does not splat elements

Added by nobu (Nobuyoshi Nakada) almost 7 years ago. Updated almost 6 years ago.

Status:
Closed
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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0