Project

General

Profile

Actions

Bug #14251

closed

String insert changing value of other string

Added by ricardovsilva (Ricardo Silva) over 6 years ago. Updated over 6 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
[ruby-core:84530]

Description

foo = 'abc'
bar = foo
bar.insert(1, d)

puts foo 'adbc'
puts bar 'adbc'

The example above should only affect bar variable. It leads to an error by programmer.

A bypass that I found is to do:

foo = 'aaa'
bar = String.new foo
bar.insert(1, 'd')
puts foo #aaa
puts bar #adaa
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0