From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id D155A1F5AE for ; Tue, 28 Jul 2020 23:03:29 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A9CA8120A6D; Wed, 29 Jul 2020 08:02:55 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4F216120A60 for ; Wed, 29 Jul 2020 08:02:53 +0900 (JST) Received: by filterdrecv-p3mdw1-75c584b9c6-t2pql with SMTP id filterdrecv-p3mdw1-75c584b9c6-t2pql-19-5F20AEB8-32 2020-07-28 23:03:20.150023236 +0000 UTC m=+2786027.267229147 Received: from herokuapp.com (unknown) by ismtpd0014p1iad2.sendgrid.net (SG) with ESMTP id -YkI3W9WR4CTP3x4AqlILA for ; Tue, 28 Jul 2020 23:03:20.069 +0000 (UTC) Date: Tue, 28 Jul 2020 23:03:20 +0000 (UTC) From: tyler@tylerrick.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75173 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 6596 X-Redmine-Issue-Author: robin850 X-Redmine-Issue-Assignee: matz X-Redmine-Sender: TylerRick 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: =?us-ascii?Q?IcCRMXAFltei8rJtVDRSFnq67BH0hQz3m6H4cvw9VQXG4leEte7gzjzlUX=2F98B?= =?us-ascii?Q?=2FEraNceu2RDCRKcwIHwDpZ9Y8TwwVL0gt6jR2Qm?= =?us-ascii?Q?Ek9gY7PEGAquw6aXhW+zWkQzZWSzIr=2FBnEVCHfg?= =?us-ascii?Q?K1Zog8jd=2FdUZVDZx3qPIONSFyGaahzfqTFeT4h1?= =?us-ascii?Q?hg1SVEK86LmMN5fvrGMXwLu2Lh0jvOIWU8ZIdNh?= =?us-ascii?Q?SUD79sHzcrekzcfQk=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99377 Subject: [ruby-core:99377] [Ruby master Feature#6596] New method for Arrays : Array#indexes 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 #6596 has been updated by TylerRick (Tyler Rick). I'm not very good at writing C, but here is a reference implementation in Ruby (plus unit tests) in case it's helpful: https://github.com/rubyworks/facets/pull/294/files This version adds `indexes` (aliased as `index_all`) to `Array`, `Enumerable`, and `Enumerator::Lazy` for completeness. ---------------------------------------- Feature #6596: New method for Arrays : Array#indexes https://bugs.ruby-lang.org/issues/6596#change-86782 * Author: robin850 (Robin Dupret) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- Hello 5 days ago, I submitted a pull request on Github which provides a new method for the array objects which is Array#indexes. I have fist edit the Array#index method in order it to return an array of indexes and not a single index (which is the first occurrence it finds). I found it more logical but a user (trans) tells us that it could break the contract of Array#index so I decided to move it into Array#indexes. Eric (drbrain) tells me I should reasonning why I want to add this method ; it's just a point of view : I don't really understand why Array#index return a single index if the parameter is in the array several times. Examples a = [1, 2, 3, 1] a.indexes(1) Return : [0, 3] a.index(1) Return : 0 In my opinion, it's not really logical, 1 is in the array twice Moreover, this pull request doesn't beak anything because we don't edit the Array#index method so programms which were created with previous version of Ruby will work. I hope my post is complete. Have a nice day. -- https://bugs.ruby-lang.org/