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=AWL,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 4701020899 for ; Sat, 12 Aug 2017 04:01:48 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6065A1207F5; Sat, 12 Aug 2017 13:01:46 +0900 (JST) Received: from sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3A524120751 for ; Sat, 12 Aug 2017 13:01:44 +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=M4vq+qbGhZkVUyR6FQ0oSGrKakI=; b=waos+snIiZibUnJQAv q8HujSGFTxTYM5UsNNzQN3AKy9TCmE04o0Cqsm6cCnUHplWR4SEhm6PaTyiKyfyA ngHQhYEWBSfhLEs8hWakySDwAkCjURf8vyM896qmmHErAutyzztpg8QKJWfgT4dk uLqVBg6RBxnT2Iqr/LtIvSlC0= Received: by filter0028p3mdw1.sendgrid.net with SMTP id filter0028p3mdw1-18305-598E7DA5-15 2017-08-12 04:01:41.253107002 +0000 UTC Received: from herokuapp.com (ec2-54-196-115-177.compute-1.amazonaws.com [54.196.115.177]) by ismtpd0038p1mdw1.sendgrid.net (SG) with ESMTP id iVoWsF8KQ6-W10eV9io9Jg for ; Sat, 12 Aug 2017 04:01:41.221 +0000 (UTC) Date: Sat, 12 Aug 2017 04:01:41 +0000 (UTC) From: shevegen@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 57403 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13807 X-Redmine-Issue-Author: sawa X-Redmine-Sender: shevegen 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4Xn+Kya3q+smG9iWPhnNeXAo1ysuU21cpmsF LnhxwmCz5gHDkJb0tG3lGkn6W/HbTKfIBzKPm4gLQEkDVEp7YOfoNxfILh6RsbbxjSc8BKcmwo47Y+ MPYjtJVFai36VaRx7sdajgAwkcYsEDsj6vPHNaWVeA7awtH97i9LFpE9tw== X-ML-Name: ruby-core X-Mail-Count: 82357 Subject: [ruby-core:82357] [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 updated by shevegen (Robert A. Heiler). I have no particular pro or con opinion about your proposal, but I just want to say that the last variant is not very pretty. The lonely guy operator staring at the dot before him is pressed hard against the wall behind him there, the "}" character! ---------------------------------------- Feature #13807: A method to filter the receiver against some condition https://bugs.ruby-lang.org/issues/13807#change-66150 * 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/