From: danieldasilvaferreira@... Date: 2017-12-28T00:58:52+00:00 Subject: [ruby-core:84538] [Ruby trunk Bug#14251] String insert changing value of other string Issue #14251 has been updated by dsferreira (Daniel Ferreira). I advise you to put this ���issues��� you find as questions in ruby talk before opening ruby core bugs. In ruby objects are mutable and passed by reference. When you do `bar = bar + 'ccc'` you are allocating a new reference to bar object. The output object of the `+` operation. Hope this helps. Ruby talk is the right place for this things. Welcome to ruby world! ---------------------------------------- Bug #14251: String insert changing value of other string https://bugs.ruby-lang.org/issues/14251#change-69067 * Author: ricardovsilva (Ricardo Silva) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- ~~~ ruby 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: ~~~ ruby foo = 'aaa' bar = String.new foo bar.insert(1, 'd') puts foo #aaa puts bar #adaa ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: