Issue #8499 has been updated by nobu (Nobuyoshi Nakada).


I've missed the returned values until I've implemented it actually.

In ActiveSupport:
* Hash#slice! keeps the given keys and returns removed key/value pairs.
* Hash#except! removes the given keys and returns self.

In this proposal:
* Hash#slice! removes the given keys and returns removed key/value pairs.
* Hash#except! is same as ActiveSupport.

Existing methods:
* Hash#select! keeps the given (by the block) keys and returns self or nil.
* Hash#reject! removes the given (by the block) keys and returns self or nil.

I don't think changing the result semantics by if any arguments are given is good idea.
What I've thoutht about Hash#slice! was Hash#extract! in ActiveSupport actually.
So what about Hash#extract, Hash#except and those !-versions?

----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-40725

Author: mrkn (Kenta Murata)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


=begin RD
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!}))
=end


-- 
http://bugs.ruby-lang.org/