From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,SPF_PASS, T_DKIM_INVALID shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 3131320899 for ; Thu, 10 Aug 2017 11:39:16 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5D6F3120808; Thu, 10 Aug 2017 20:39:12 +0900 (JST) Received: from sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 72967120801 for ; Thu, 10 Aug 2017 20:39:10 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=kFZW68qmX4YH/Qj1M/XgF1K6A1A=; b=tKFQAZdGu0p0amG+Hk tXFkLXzng/nnzRPKaEBZM1Oj7qpcBpJSK3/nCh1WPUk1TdPc8XT6qG+y+g2fPEfc XxT6enNpji67GUk+W4V6CyPGPemBzt5vamegpYACktE6BY6grvMF+/bI+ZXxkpgh GXQFO1wSpKNTdHC5UIMB3Fd2Y= Received: by filter0004p3mdw1.sendgrid.net with SMTP id filter0004p3mdw1-32289-598C45D9-D 2017-08-10 11:39:05.267662444 +0000 UTC Received: from herokuapp.com (ec2-50-19-160-32.compute-1.amazonaws.com [50.19.160.32]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id iSj-9or9Q0Cx5HlN2BVZVw for ; Thu, 10 Aug 2017 11:39:05.214 +0000 (UTC) Date: Thu, 10 Aug 2017 11:39:05 +0000 (UTC) From: pike.jc@googlemail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 57372 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13797 X-Redmine-Issue-Author: gggfx X-Redmine-Sender: gggfx X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS6hrqXPOQIA0YmN+HER+Eq6Y3h84szlZapCHr ETp+CFbPKtnYhdu5GUwxA+KbO6Em6YLMnu8ZW4NY6ZjqDkSd1kGlEgTdjFM/sdnBoghOYJ+rgdW/a3 ORjUN/SLaJ7C6zQ7Ms8yPLAi6jDw4OeXd76G6jOyyCurCShjZIFrvmLzpA== X-ML-Name: ruby-core X-Mail-Count: 82326 Subject: [ruby-core:82326] [Ruby trunk Bug#13797] Using .push on an 2d array class-instance variable causes the whole array to be overwritten with the .push value; is this a bug? X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #13797 has been reported by gggfx (James Pike). ---------------------------------------- Bug #13797: Using .push on an 2d array class-instance variable causes the whole array to be overwritten with the .push value; is this a bug? https://bugs.ruby-lang.org/issues/13797 * Author: gggfx (James Pike) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.2.6p396 (2016-11-15 revision 56800) [x64-mingw32] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- I was building a class to hold results for analysis 'cells' in a model; each 'cell' is a position in an array, with each result stored in a sub-array - this collates multiple results per cell which can then be iterated through later for model interactions. I created this as a class (my data is addressed by time,x,y and z coordinates; my class writers and readers convert t-x-y-z into a position on a 1d array, this is faster than named instance variables). When it comes to pushing the data into the instance array variable it causes *all* the slots of the array to be pushed with the value. This is my first bug report and I'm newish to Ruby so I apologise if I've missed any key information. I attach code with a test-example I wrote which demonstrates the behaviour in question. ## NORMAL CASE **testArray** = [[],[],[],[],[]] **testArrayShouldLookLike** = [[*result1*],[],[],[],[]] **testArrayCanThenLookLike** = [[*result1*, *result2*],[],[],[],[]] etc. ## CLASS CASE **def** write(position, data) @testArray[position].push(data) **end** **testArrayComesOutAs** = [[*result1*],[*result1*],[*result1*],[*result1*],[*result1*]] ---Files-------------------------------- Class bug_JP.rb (1.13 KB) -- https://bugs.ruby-lang.org/