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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, T_SPF_PERMERROR,UNPARSEABLE_RELAY,URIBL_GREY shortcircuit=no autolearn=no 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 7F5311F54E for ; Wed, 3 Aug 2022 04:53:07 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sendgrid.me header.i=@sendgrid.me header.b="qE2PVY7n"; dkim-atps=neutral Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id DBB961218DD; Wed, 3 Aug 2022 13:53:00 +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 9FD81121895 for ; Wed, 3 Aug 2022 13:52:58 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sendgrid.me; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc; s=smtpapi; bh=Ywhf8EzGB0dxpAJwEuylgeRhzlIzBQaB6RBbUtApZO0=; b=qE2PVY7nwjVxxdv0DIcbcV+RM3TV1jmbhUmd4y0yW+xjqv6nPIgGH5+83yb+kxyIJjbg EAi8jj4L5g1N7TW1i6VpuoiETS/oSaZXvujSBs3r1VuAhpJ1q31zThMJMCxrpj6CLn3F5R OTbWpqeilizWFtUs53oMzM/oGdLYuNUtM= Received: by filterdrecv-68b46c5bd4-qzql7 with SMTP id filterdrecv-68b46c5bd4-qzql7-1-62E9FF27-1F 2022-08-03 04:52:56.018025145 +0000 UTC m=+1068477.966390289 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-2 (SG) with ESMTP id vwn5opc_TDW01AybR9R-lw for ; Wed, 03 Aug 2022 04:52:55.892 +0000 (UTC) Date: Wed, 03 Aug 2022 04:52:56 +0000 (UTC) From: "mrkn (Kenta Murata)" Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 18953 X-Redmine-Issue-Author: ttanimichi X-Redmine-Sender: mrkn 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-Redmine-MailingListIntegration-Message-Ids: 85826 X-SG-EID: =?us-ascii?Q?CCvClhxo9hyF4lBzgp+05QZau8TZPes8xSVRVCb+vj4KaFFYTdsG43HTZQxxd7?= =?us-ascii?Q?KIZPKzSzBQAaRsmg1MpNsCVIenlNT4RicN9ZhvH?= =?us-ascii?Q?W3eF7CATz4m2egah1YpSc6tvLd6046keFzfrmpf?= =?us-ascii?Q?tMpek4huSKskPXrTjRVdFm+PHq2htznxWN9OHZO?= =?us-ascii?Q?sfuO4etGC2YRPU1T5=2FhLkzwpVzzwV2T2t9HJkYj?= =?us-ascii?Q?fCbeGAozaIdgEhbF+1HSYb2n8=2FcxIYbHEt4WEkn?= =?us-ascii?Q?rDSMshWggl6V=2FUv6Q=2Fqfw=3D=3D?= To: ruby-dev@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-dev X-Mail-Count: 51190 Subject: [ruby-dev:51190] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one X-BeenThere: ruby-dev@ruby-lang.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Ruby developers \(Japanese\)" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Reply-To: "Ruby developers \(Japanese\)" Errors-To: ruby-dev-bounces@ruby-lang.org Sender: "ruby-dev" Issue #18953 has been updated by mrkn (Kenta Murata). I hope this behavior should be expected. However, `sort_by`, `max_by`, and `min_by` call the given blocks even if the receiver array has only one item. ``` irb(main):001:0> [42].sort_by { _1.foo } (irb):1:in `block in ': undefined method `foo' for 42:Integer (NoMethodError) Did you mean? floor from (irb):1:in `each' from (irb):1:in `sort_by' from (irb):1:in `
' from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `' from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load' from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `
' irb(main):002:0> [42].max_by { _1.foo } (irb):2:in `block in ': undefined method `foo' for 42:Integer (NoMethodError) Did you mean? floor from (irb):2:in `each' from (irb):2:in `max_by' from (irb):2:in `
' from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `' from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load' from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `
' irb(main):003:0> [42].min_by { _1.foo } (irb):3:in `block in ': undefined method `foo' for 42:Integer (NoMethodError) Did you mean? floor from (irb):3:in `each' from (irb):3:in `min_by' from (irb):3:in `
' from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `' from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load' from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `
' ``` ---------------------------------------- Bug #18953: `Array#uniq` doesn't evaluate the given block when the size of the array is one https://bugs.ruby-lang.org/issues/18953#change-98570 * Author: ttanimichi (Tsukuru Tanimichi) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `Array#uniq` doesn't evaluate the given block when the size of the array is one. Is this expected behavior? ``` $ ruby -e '[42, 43].uniq { _1.foo }; puts true' -e:1:in `block in
': undefined method `foo' for 42:Integer (NoMethodError) [42, 43].uniq { _1.foo }; puts true ^^^^ Did you mean? floor from -e:1:in `uniq' from -e:1:in `
' ``` ``` $ ruby -e '[42].uniq { _1.foo }; puts true' true ``` -- https://bugs.ruby-lang.org/