From: nobu@... Date: 2014-06-22T15:14:39+00:00 Subject: [ruby-core:63275] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport Issue #8499 has been updated by Nobuyoshi Nakada. Description updated Another name, `Hash#only`. http://blog.s21g.com/articles/228 ---------------------------------------- Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport https://bugs.ruby-lang.org/issues/8499#change-47322 * Author: Kenta Murata * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto * Category: core * Target version: current: 2.2.0 ---------------------------------------- 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) -- https://bugs.ruby-lang.org/