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=-3.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,SPF_PASS,T_DKIM_INVALID shortcircuit=no autolearn=ham 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 D7F15202DD for ; Thu, 19 Oct 2017 07:29:00 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D37901209E5; Thu, 19 Oct 2017 16:28:59 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4E71F1209E1 for ; Thu, 19 Oct 2017 16:28:58 +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=21wRFEBVHVuL8T8KFFfaRgNFLsA=; b=nA4NF9B5WFEWCW0qU+ pQyR1Yu1ltH9giBusUlmYS3JmsvueMo8/Rb+8dGwHtvDnC/ibYwgtYQxqyFS3T8Q hGaxJLyJwEr/v2OoI5ZtEL+wibl+tnrNr6PcRuEicO1mjWdoxeUmmLi63apyR01w tyuL9Vcpf0B0CM4d/sbTzXLcI= Received: by filter0008p3iad2.sendgrid.net with SMTP id filter0008p3iad2-25610-59E85437-A 2017-10-19 07:28:55.250922554 +0000 UTC Received: from herokuapp.com (ec2-54-80-141-139.compute-1.amazonaws.com [54.80.141.139]) by ismtpd0019p1iad2.sendgrid.net (SG) with ESMTP id SqhLmb2CSF-thXA-TiC6Iw Thu, 19 Oct 2017 07:28:55.250 +0000 (UTC) Date: Thu, 19 Oct 2017 07:28:55 +0000 (UTC) From: knu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 58489 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 8499 X-Redmine-Issue-Author: mrkn X-Redmine-Issue-Assignee: matz X-Redmine-Sender: knu 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7DAX4DAkSSgPOrJSmsCiEBu6+9xKBti40JCM /gRUTanEvP8rngOFHPqGrwxwpIFlrb66lYFdG6KeQ4O5GYT3jNJKbOaOtvxm3l/hWpqlbMV7zpIp9k +PVZSS99bmKULvupv5nlC2iwmrV4hofj0e/WfJV5mKqLWhHGT0YcGipAMg== X-ML-Name: ruby-core X-Mail-Count: 83381 Subject: [ruby-core:83381] [Ruby trunk Feature#8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport 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 #8499 has been updated by knu (Akinori MUSHA). One concern is that Array#slice! returns deleted elements whereas this Hash#slice! would return pairs left after slicing. ---------------------------------------- Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport https://bugs.ruby-lang.org/issues/8499#change-67342 * Author: mrkn (Kenta Murata) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: 2.5 ---------------------------------------- According to my experiences, the following two idioms often appeare in application codes. 1. `hash = other_hash.select { |k, | [:key1, :key2, :key3].include? k }` 2. `hash = other_hash.reject { |k, | [:key1, :key2, :key3].include? k }` On Rails, they can be written in the following forms by using ActiveSupport's features. 1. `hash = other_hash.slice(:key1, :key2, :key3)` 2. `hash = other_hash.except(:key1, :key2, :key3)` I think the latter forms are shorter and more readable than the former ones. So I propose to import the following methods from ActiveSupport: * `Hash#slice` * `Hash#slice!` * `Hash#except` * `Hash#except!` ---Files-------------------------------- patch.diff (4.05 KB) patch2.diff (4.07 KB) patch3.diff (4.04 KB) patch4.diff (4.5 KB) -- https://bugs.ruby-lang.org/