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 C9B191F934 for ; Mon, 26 Oct 2020 04:36:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id AF9C5120A32; Mon, 26 Oct 2020 13:36:17 +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 5B829120A2F for ; Mon, 26 Oct 2020 13:36:15 +0900 (JST) Received: by filterdrecv-p3iad2-64988c98cc-jcjwt with SMTP id filterdrecv-p3iad2-64988c98cc-jcjwt-20-5F965264-A 2020-10-26 04:36:52.175633228 +0000 UTC m=+200513.963254547 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-0 (SG) with ESMTP id Lsw2oOg0QCWDWZg3VZZN5A for ; Mon, 26 Oct 2020 04:36:52.146 +0000 (UTC) Date: Mon, 26 Oct 2020 04:36:52 +0000 (UTC) From: ko1@atdot.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76419 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 11808 X-Redmine-Issue-Author: BenOlive X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: ko1 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?fVTMYOBjtdvXNcWwrscBhLsHItUXVK5L4mtnq0mdcRfygRXZHKDJyxrjNEr4fZ?= =?us-ascii?Q?xIex03U468SMfBL3Cf0vXcI8lNtslRk01Yt=2FRAh?= =?us-ascii?Q?Xl4bBocKlBqJMHdAx46boVzYziWefvRks=2FWsLHA?= =?us-ascii?Q?TxvcYE7F7hZL56a70HYZ5W6cPGzYmzBUxaRWAWK?= =?us-ascii?Q?Vv6k0mSmiR5z2lhZYPb8Dt2gte0lPHNvjGQ=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100548 Subject: [ruby-core:100548] [Ruby master Bug#11808] Different behavior between Enumerable#grep and Array#grep 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 #11808 has been updated by ko1 (Koichi Sasada). Sorry we need more time to consider. ---------------------------------------- Bug #11808: Different behavior between Enumerable#grep and Array#grep https://bugs.ruby-lang.org/issues/11808#change-88176 * Author: BenOlive (Ben Olive) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Regex special global variables are available within the block for `Array#grep`, but are nil within the block for `Enumerable#grep`. Here is an example that explains it better: ~~~ruby class Test include Enumerable def each return enum_for(:each) unless block_given? yield "Hello" yield "World" end end enum = Test.new array = ["Hello", "World"] enum.grep(/^(.)/) {$1} # => [nil, nil] array.grep(/^(.)/) {$1} # => ["H", "W"] ~~~ Tested on 2.0.0, 2.1.5, & 2.2.2 -- https://bugs.ruby-lang.org/