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.8 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_PASS 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 70463211B5 for ; Thu, 14 Feb 2019 04:44:55 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A3493121959; Thu, 14 Feb 2019 13:44:51 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 96B251210B9 for ; Thu, 14 Feb 2019 13:44:48 +0900 (JST) Received: by filter0099p3las1.sendgrid.net with SMTP id filter0099p3las1-24754-5C64F23E-4 2019-02-14 04:44:46.212305999 +0000 UTC m=+6535.867867194 Received: from herokuapp.com (ec2-54-224-197-248.compute-1.amazonaws.com [54.224.197.248]) by ismtpd0046p1iad1.sendgrid.net (SG) with ESMTP id rtZjIeWETM-p29l2-tuuDw for ; Thu, 14 Feb 2019 04:44:45.949 +0000 (UTC) Date: Thu, 14 Feb 2019 04:44:47 +0000 (UTC) From: nobu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66994 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 7394 X-Redmine-Issue-Author: zzak X-Redmine-Issue-Assignee: nobu X-Redmine-Sender: nobu 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5vmBFExxfihOljWAAgFvzxMJeI1IIuEMFi4v K0iFNT1ULgml+i5kCgOAyKnksXpJqkBS51+Xj7M8h8NbpoyqK6yE3i5sYykTIMIcaiSI/atLVh7rQu HX+3GmQpc22XvraJ14WJ2W4yJcb7Uq2c3sHlUiOtPRAyOfcuzO1/vcdkgQ== X-ML-Name: ruby-core X-Mail-Count: 91542 Subject: [ruby-core:91542] [Ruby trunk Feature#7394] Enumerable#find ifnone parameter could be non-callable 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 #7394 has been updated by nobu (Nobuyoshi Nakada). Description updated Currently, it is not able to distinguish from the case a hash is given as an ordinal argument. So there still is a possibility to break a compatibility. ---------------------------------------- Feature #7394: Enumerable#find ifnone parameter could be non-callable https://bugs.ruby-lang.org/issues/7394#change-76805 * Author: zzak (Zachary Scott) * Status: Assigned * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: ---------------------------------------- from github: https://github.com/ruby/ruby/pull/186 In trunk the `Enumerable#find` method `ifnone` parameter has to be callable or `nil`. I found that sometimes I want to return a simple value without wrapping it in a proc. This pull request adds support for non-callable defaults when no items match. ```ruby a = [1, 2, 3] ``` The current behavior ```ruby a.find(proc { :foo }) { |x| x > 3 } #=> :foo ``` With patch ```ruby a.find(0) { |x| x > 3 } #=> 0 ``` ---Files-------------------------------- enumerable_find_noncallable.patch (3.45 KB) -- https://bugs.ruby-lang.org/