Project

General

Profile

Actions

Backport #5124

closed

foo = [*bar] implies foo.equal?(bar)

Added by adgar (Michael Edgar) over 12 years ago. Updated almost 12 years ago.

Status:
Closed
[ruby-core:38625]

Description

I just ran into this as a result of some slightly sloppy coding, but it did disagree with my internal assumptions.

Normally, I expect the Array literal syntax to create a new object, every time. So when I rewrote some code and ended up with something similar to the following, my tests broke, and I'm not sure that's how it should be. Here's the reduced test case:

some_ary = [1, 2, 3]
bar = [*some_ary]
bar << 4

p bar

[1, 2, 3, 4]
p some_ary
[1, 2, 3, 4]

I see it's clearly taking an opportunity for optimization, so I'm more than happy to hear that as a reason for rejecting this. It does warrant documentation somewhere, though, I'd say. Not sure where that documentation would go.


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #1125: [*x] (array consisting only of a splat) does not necessarily return a new arrayClosednobu (Nobuyoshi Nakada)02/07/2009Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0