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 5F38820899 for ; Fri, 11 Aug 2017 20:38:20 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C29EB1207F5; Sat, 12 Aug 2017 05:38:17 +0900 (JST) Received: from sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id A7ED6120751 for ; Sat, 12 Aug 2017 05:38:15 +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=5zH4dhSxcmhLgyDwngJSpssqgU4=; b=stJr7VUPf029zzNO8v NVjaFoc+xZw5CsXdpuhQ1k5WnF75UD5CtGl8bg3r7SJsulRRJfkp9uagVGTJ+iSg nm+bUMY8MIbN+XIdb03jOuOGrOG4mhh1uQWVoLLYgQ0K4gx4XGL4RJIBzgZ/iGHm W5kP0JH5FN2HacdBtG9tFMDsg= Received: by filter0021p3mdw1.sendgrid.net with SMTP id filter0021p3mdw1-25702-598E15B2-D 2017-08-11 20:38:10.263738367 +0000 UTC Received: from herokuapp.com (ec2-54-196-115-177.compute-1.amazonaws.com [54.196.115.177]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id vOdXk41sSNahyGHKCIO5Uw for ; Fri, 11 Aug 2017 20:38:10.190 +0000 (UTC) Date: Fri, 11 Aug 2017 20:38:12 +0000 (UTC) From: sawadatsuyoshi@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 57399 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13807 X-Redmine-Issue-Author: sawa X-Redmine-Sender: sawa 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS5cpBBe+BF//puXc/CoKGcVdxodsHEeghsNSn IOVCyaJ876wmqjUsc/zSaOvTnxZgh9Gks0erQ95mKzc70EELzxQTgZo8lFxYQ5WILhASu0nxNhsaav m1MlThRIYRgaZoGijzlb6jXnJWUHaY4SWYfQXVV6zVcyoRoPvCdYOqdLVA== X-ML-Name: ruby-core X-Mail-Count: 82353 Subject: [ruby-core:82353] [Ruby trunk Feature#13807] A method to filter the receiver against some condition 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 #13807 has been reported by sawa (Tsuyoshi Sawada). ---------------------------------------- Feature #13807: A method to filter the receiver against some condition https://bugs.ruby-lang.org/issues/13807 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- I frequently see code that uses some value if that value satisfies a certain condition, and something else otherwise. ```ruby a.some_condition ? a : b ``` And in most cases, the value of `a` is non-nil when the condition is satisfied. I propose to have a method, perhaps named `verify`, which would implemented to be equivalent to this definition: ```ruby class Object def verify self if yield(self) end end ``` Then, we can write the expression above (assuming `a` is non-nil when the condition is satisfied) like this: ```ruby a.verify{|a| a.some_condition} || b ``` Perhaps it would also be useful to do something like: ```ruby a.verify{|a| a.some_condition}&.chaining_of_more_methods ``` -- https://bugs.ruby-lang.org/