Project

General

Profile

Actions

Bug #800

closed

Problem with Array class

Added by Francoys_Proulx (Francois Proulx) over 15 years ago. Updated about 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
Backport:
[ruby-core:20158]

Description

=begin
If you test this simple program, you will see why array should be dup on assignment ...

a=1
b=1
c=[a,b]

def foo(x)
  x[0] +=1
  x[1] +=1
end

d = c
e = d
f = e

foo(f)

p c[0],c[1]

=end

Actions #1

Updated by radarek (Radosław Bułat) over 15 years ago

=begin
No it shouldn't. Variables keeps references to objects, not objects itself. It is up to programmer if he wants to pass reference (as ruby do by default) or make clone (duplicate) of it.
=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 15 years ago

  • Status changed from Open to Rejected

=begin
No, it shouldn't. It will destroy the object model of the language.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0