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=-2.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 88B5C1F5A1 for ; Tue, 12 Nov 2019 20:13:06 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A03A4120A29; Wed, 13 Nov 2019 05:12:55 +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 3585412092C for ; Wed, 13 Nov 2019 05:12:53 +0900 (JST) Received: by filter0121p3las1.sendgrid.net with SMTP id filter0121p3las1-24819-5DCB1247-29 2019-11-12 20:12:55.455402968 +0000 UTC m=+91093.288752582 Received: from herokuapp.com (unknown [54.162.83.60]) by ismtpd0015p1iad1.sendgrid.net (SG) with ESMTP id rPL9gsyYSeGV3YqgCgEvyw for ; Tue, 12 Nov 2019 20:12:55.113 +0000 (UTC) Date: Tue, 12 Nov 2019 20:12:55 +0000 (UTC) From: non.dmitriy@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71452 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16341 X-Redmine-Issue-Author: Nondv X-Redmine-Sender: Nondv 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?EtUBU5pNPGGF695WqpG6VxCA85Kr9QQx+VRnpZEtiFc2uGj5uPNV2oyYv9qLwr?= =?us-ascii?Q?7hWmUzM0=2FsjbBj=2FmB3ORC9F9wlxTvNBXS6eur9M?= =?us-ascii?Q?QtIMONTLX7nhHu5V7TASQeqnC+zHQ71INNVwZ=2FB?= =?us-ascii?Q?ajI8wMA9sBvhgO8kIs7Imw3zoLIm1pR21Ilxnp7?= =?us-ascii?Q?O8t2wsXLpDTE3FTmav3KnlYBR9=2Fu8mDKDpA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95823 Subject: [ruby-core:95823] [Ruby master Feature#16341] Proposal: Set#to_proc and Hash#to_proc 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 #16341 has been updated by Nondv (Dmitry Non). shan (Shannon Skipper) wrote: > This already works! I can't believe I'm so oblivious :D ---------------------------------------- Feature #16341: Proposal: Set#to_proc and Hash#to_proc https://bugs.ruby-lang.org/issues/16341#change-82652 * Author: Nondv (Dmitry Non) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- ``` ruby class Set def to_proc -> (x) { include?(x) } # or method(:include?).to_proc end end ``` Usage: ```ruby require 'set' banned_numbers = Set[0, 5, 7, 9] (1..10).reject(&banned_numbers) # ===> [1, 2, 3, 4, 6, 8, 10] ``` **UPD** also for hash: ```ruby class Hash def to_proc ->(key) { self[key] } end end dogs = ['Lucky', 'Tramp', 'Lady'] favourite_food = { 'Lucky' => 'salmon', 'Tramp' => 'pasta', 'Lady' => 'pasta' } food_to_order = dogs.map(&favourite_food) ``` -- https://bugs.ruby-lang.org/