ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
@ 2013-06-06  7:12 mrkn (Kenta Murata)
  2013-06-06  7:13 ` [ruby-core:55331] [ruby-trunk - Feature #8499] " sorah (Shota Fukumori)
                   ` (26 more replies)
  0 siblings, 27 replies; 30+ messages in thread
From: mrkn (Kenta Murata) @ 2013-06-06  7:12 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been reported by mrkn (Kenta Murata).

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

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.reject(: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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55331] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
@ 2013-06-06  7:13 ` sorah (Shota Fukumori)
  2013-06-06  7:21 ` [ruby-core:55332] Re: [ruby-trunk - Feature #8499][Assigned] " Zachary Scott
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: sorah (Shota Fukumori) @ 2013-06-06  7:13 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by sorah (Shota Fukumori).


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

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.reject(: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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55332] Re: [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
  2013-06-06  7:13 ` [ruby-core:55331] [ruby-trunk - Feature #8499] " sorah (Shota Fukumori)
@ 2013-06-06  7:21 ` Zachary Scott
  2013-06-06  7:27 ` [ruby-core:55333] [ruby-trunk - Feature #8499] " nobu (Nobuyoshi Nakada)
                   ` (24 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Zachary Scott @ 2013-06-06  7:21 UTC (permalink / raw
  To: ruby-core@ruby-lang.org

Hello,

On Thu, Jun 6, 2013 at 4:12 PM, mrkn (Kenta Murata) <muraken@gmail.com> wrote:
> 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.reject(:key1, :key2, :key3}}))

Do you mean "other_hash.except(...)"? There is already Hash#reject

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55333] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
  2013-06-06  7:13 ` [ruby-core:55331] [ruby-trunk - Feature #8499] " sorah (Shota Fukumori)
  2013-06-06  7:21 ` [ruby-core:55332] Re: [ruby-trunk - Feature #8499][Assigned] " Zachary Scott
@ 2013-06-06  7:27 ` nobu (Nobuyoshi Nakada)
  2013-06-06  7:28 ` [ruby-core:55334] " mrkn (Kenta Murata)
                   ` (23 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-06-06  7:27 UTC (permalink / raw
  To: ruby-core


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

Description updated


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

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.reject(: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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55334] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (2 preceding siblings ...)
  2013-06-06  7:27 ` [ruby-core:55333] [ruby-trunk - Feature #8499] " nobu (Nobuyoshi Nakada)
@ 2013-06-06  7:28 ` mrkn (Kenta Murata)
  2013-06-06  7:51 ` [ruby-core:55335] " mrkn (Kenta Murata)
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: mrkn (Kenta Murata) @ 2013-06-06  7:28 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by mrkn (Kenta Murata).


zzak (Zachary Scott) wrote:
> Hello,
>  
>  On Thu, Jun 6, 2013 at 4:12 PM, mrkn (Kenta Murata) <muraken@gmail.com> wrote:
>  > 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.reject(:key1, :key2, :key3}}))
>  
>  Do you mean "other_hash.except(...)"? There is already Hash#reject

Yes, It's my mistake!

How can I edit the issue description?
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-39741

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.reject(: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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55335] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (3 preceding siblings ...)
  2013-06-06  7:28 ` [ruby-core:55334] " mrkn (Kenta Murata)
@ 2013-06-06  7:51 ` mrkn (Kenta Murata)
  2013-06-06  7:59 ` [ruby-core:55336] " nobu (Nobuyoshi Nakada)
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: mrkn (Kenta Murata) @ 2013-06-06  7:51 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by mrkn (Kenta Murata).

Description updated

I could fix the description.
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-39742

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55336] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (4 preceding siblings ...)
  2013-06-06  7:51 ` [ruby-core:55335] " mrkn (Kenta Murata)
@ 2013-06-06  7:59 ` nobu (Nobuyoshi Nakada)
  2013-06-06  8:10 ` [ruby-core:55338] " mrkn (Kenta Murata)
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-06-06  7:59 UTC (permalink / raw
  To: ruby-core


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


Or enhance the existing methods?
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-39743

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55338] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (5 preceding siblings ...)
  2013-06-06  7:59 ` [ruby-core:55336] " nobu (Nobuyoshi Nakada)
@ 2013-06-06  8:10 ` mrkn (Kenta Murata)
  2013-06-06  8:20 ` [ruby-core:55339] " charliesome (Charlie Somerville)
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: mrkn (Kenta Murata) @ 2013-06-06  8:10 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by mrkn (Kenta Murata).


nobu (Nobuyoshi Nakada) wrote:
> Or enhance the existing methods?

I think Hash#[] with the multiple arguments can be an alternative of Hash#slice.

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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55339] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (6 preceding siblings ...)
  2013-06-06  8:10 ` [ruby-core:55338] " mrkn (Kenta Murata)
@ 2013-06-06  8:20 ` charliesome (Charlie Somerville)
  2013-06-06 13:43 ` [ruby-core:55342] " nobu (Nobuyoshi Nakada)
                   ` (18 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: charliesome (Charlie Somerville) @ 2013-06-06  8:20 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by charliesome (Charlie Somerville).


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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55342] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (7 preceding siblings ...)
  2013-06-06  8:20 ` [ruby-core:55339] " charliesome (Charlie Somerville)
@ 2013-06-06 13:43 ` nobu (Nobuyoshi Nakada)
  2013-06-06 13:45 ` [ruby-core:55343] " rosenfeld (Rodrigo Rosenfeld Rosas)
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-06-06 13:43 UTC (permalink / raw
  To: ruby-core


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


mrkn (Kenta Murata) wrote:
> I think Hash#[] with the multiple arguments can be an alternative of Hash#slice.

Hash#[] should return the values, not the pairs.
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-39749

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55343] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (8 preceding siblings ...)
  2013-06-06 13:43 ` [ruby-core:55342] " nobu (Nobuyoshi Nakada)
@ 2013-06-06 13:45 ` rosenfeld (Rodrigo Rosenfeld Rosas)
  2013-06-06 15:15 ` [ruby-core:55344] " prijutme4ty (Ilya Vorontsov)
                   ` (16 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: rosenfeld (Rodrigo Rosenfeld Rosas) @ 2013-06-06 13:45 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55344] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (9 preceding siblings ...)
  2013-06-06 13:45 ` [ruby-core:55343] " rosenfeld (Rodrigo Rosenfeld Rosas)
@ 2013-06-06 15:15 ` prijutme4ty (Ilya Vorontsov)
  2013-06-06 15:35   ` [ruby-core:55345] " Clay Trump
  2013-06-06 15:38 ` [ruby-core:55346] " mrkn (Kenta Murata)
                   ` (15 subsequent siblings)
  26 siblings, 1 reply; 30+ messages in thread
From: prijutme4ty (Ilya Vorontsov) @ 2013-06-06 15:15 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by prijutme4ty (Ilya Vorontsov).


mrkn (Kenta Murata) wrote:
> nobu (Nobuyoshi Nakada) wrote:
> > Or enhance the existing methods?
> 
> I think Hash#[] with the multiple arguments can be an alternative of Hash#slice.

There was a proposal (can't find it) to make indexing by multiple arguments to work as nested hashes so that hsh[:a,:b,:c] works as (hsh[:a] && hsh[:a][:b] && hsh[:a][:b][:c]). Your proposal automatically blocks this proposal.
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-39751

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55345] Re: [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06 15:15 ` [ruby-core:55344] " prijutme4ty (Ilya Vorontsov)
@ 2013-06-06 15:35   ` Clay Trump
  0 siblings, 0 replies; 30+ messages in thread
From: Clay Trump @ 2013-06-06 15:35 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 152 bytes --]

Yay, +1 for slice & except

BTW, makes no sense to me if h[:foo, :bar] returns keys and values in a
hash while h[:foo] returns a value.
-- 
<lay trum/>

[-- Attachment #2: Type: text/html, Size: 305 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55346] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (10 preceding siblings ...)
  2013-06-06 15:15 ` [ruby-core:55344] " prijutme4ty (Ilya Vorontsov)
@ 2013-06-06 15:38 ` mrkn (Kenta Murata)
  2013-06-06 16:50   ` [ruby-core:55347] Re: [ruby-trunk - Feature #8499][Assigned] " Zachary Scott
  2013-06-06 18:22 ` [ruby-core:55348] [ruby-trunk - Feature #8499] " vipulnsward (Vipul Amler)
                   ` (14 subsequent siblings)
  26 siblings, 1 reply; 30+ messages in thread
From: mrkn (Kenta Murata) @ 2013-06-06 15:38 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by mrkn (Kenta Murata).


prijutme4ty (Ilya Vorontsov) wrote:
> mrkn (Kenta Murata) wrote:
> > nobu (Nobuyoshi Nakada) wrote:
> > > Or enhance the existing methods?
> > 
> > I think Hash#[] with the multiple arguments can be an alternative of Hash#slice.
> 
> There was a proposal (can't find it) to make indexing by multiple arguments to work as nested hashes so that hsh[:a,:b,:c] works as (hsh[:a] && hsh[:a][:b] && hsh[:a][:b][:c]). Your proposal automatically blocks this proposal.

My proposal primaliry consists of Hash#slice, Hash#except, and bang versions of them.
Hash#[] is optional.
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-39752

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55347] Re: [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06 15:38 ` [ruby-core:55346] " mrkn (Kenta Murata)
@ 2013-06-06 16:50   ` Zachary Scott
  0 siblings, 0 replies; 30+ messages in thread
From: Zachary Scott @ 2013-06-06 16:50 UTC (permalink / raw
  To: ruby-core@ruby-lang.org

[-- Attachment #1: Type: text/plain, Size: 72 bytes --]

>
> Please update description if the proposal has changed (ie: Hash#[])

[-- Attachment #2: Type: text/html, Size: 196 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55348] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (11 preceding siblings ...)
  2013-06-06 15:38 ` [ruby-core:55346] " mrkn (Kenta Murata)
@ 2013-06-06 18:22 ` vipulnsward (Vipul Amler)
  2013-06-07  1:37 ` [ruby-core:55352] " nobu (Nobuyoshi Nakada)
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: vipulnsward (Vipul Amler) @ 2013-06-06 18:22 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by vipulnsward (Vipul Amler).


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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:55352] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (12 preceding siblings ...)
  2013-06-06 18:22 ` [ruby-core:55348] [ruby-trunk - Feature #8499] " vipulnsward (Vipul Amler)
@ 2013-06-07  1:37 ` nobu (Nobuyoshi Nakada)
  2013-07-26 13:58 ` [ruby-core:56205] " Glass_saga (Masaki Matsushita)
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-06-07  1:37 UTC (permalink / raw
  To: ruby-core


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


I meant Hash#select and Hash#reject by "the existing methods".

i.e.:

    hash = other_hash.select(:key1, :key2, :key3)
    hash = other_hash.reject(:key1, :key2, :key3)

But Hash#slice and Hash#except seems fine.

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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:56205] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (13 preceding siblings ...)
  2013-06-07  1:37 ` [ruby-core:55352] " nobu (Nobuyoshi Nakada)
@ 2013-07-26 13:58 ` Glass_saga (Masaki Matsushita)
  2013-07-27  6:22 ` [ruby-core:56220] " matz (Yukihiro Matsumoto)
                   ` (11 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Glass_saga (Masaki Matsushita) @ 2013-07-26 13:58 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by Glass_saga (Masaki Matsushita).

File patch.diff added

How about this implementation?
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-40690

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:56220] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (14 preceding siblings ...)
  2013-07-26 13:58 ` [ruby-core:56205] " Glass_saga (Masaki Matsushita)
@ 2013-07-27  6:22 ` matz (Yukihiro Matsumoto)
  2013-07-27  6:25 ` [ruby-core:56221] " znz (Kazuhiro NISHIYAMA)
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2013-07-27  6:22 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by matz (Yukihiro Matsumoto).


The slice method (Array#slice) retrieve "a slice of elements" from an Array.
Considering that, slice is *not* a good name for the behavior.

So, I prefer Nobu's idea in comment #16

    hash = other_hash.select(:key1, :key2, :key3)
    hash = other_hash.reject(:key1, :key2, :key3)

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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:56221] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (15 preceding siblings ...)
  2013-07-27  6:22 ` [ruby-core:56220] " matz (Yukihiro Matsumoto)
@ 2013-07-27  6:25 ` znz (Kazuhiro NISHIYAMA)
  2013-07-27 20:56 ` [ruby-core:56235] " nobu (Nobuyoshi Nakada)
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: znz (Kazuhiro NISHIYAMA) @ 2013-07-27  6:25 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by znz (Kazuhiro NISHIYAMA).


=begin
In attached patch.diff
 assert_equal({1=>2, 3=>4}, h.slice!(1, 3))
but ActiveSupport's h.slice!(1, 3) returns {5=>6}.

http://api.rubyonrails.org/classes/Hash.html#method-i-slice-21
=end

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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:56235] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (16 preceding siblings ...)
  2013-07-27  6:25 ` [ruby-core:56221] " znz (Kazuhiro NISHIYAMA)
@ 2013-07-27 20:56 ` nobu (Nobuyoshi Nakada)
  2013-07-28  9:26 ` [ruby-core:56242] " mrkn (Kenta Murata)
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2013-07-27 20:56 UTC (permalink / raw
  To: ruby-core


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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:56242] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (17 preceding siblings ...)
  2013-07-27 20:56 ` [ruby-core:56235] " nobu (Nobuyoshi Nakada)
@ 2013-07-28  9:26 ` mrkn (Kenta Murata)
  2013-07-29  3:24 ` [ruby-core:56252] " Glass_saga (Masaki Matsushita)
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: mrkn (Kenta Murata) @ 2013-07-28  9:26 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by mrkn (Kenta Murata).


=begin
The attached file is not a part of my proposal. It made by  Glass_saga. My proposal is the same as ActiveSupport.
=end

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

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:56252] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (18 preceding siblings ...)
  2013-07-28  9:26 ` [ruby-core:56242] " mrkn (Kenta Murata)
@ 2013-07-29  3:24 ` Glass_saga (Masaki Matsushita)
  2014-01-30  6:17 ` [ruby-core:60296] " shibata.hiroshi
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: Glass_saga (Masaki Matsushita) @ 2013-07-29  3:24 UTC (permalink / raw
  To: ruby-core


Issue #8499 has been updated by Glass_saga (Masaki Matsushita).

File patch2.diff added

I'm sorry for my wrong implementation.
patch2.diff makes Hash#slice! and #except! behave the same as ActiveSupport.
However, I think it isn't good idea to import Hash#slice! and #except! from ActiveSupport as it is.

Because:
* They returns self if no changes were made. It is inconsistent with other built-in methods like #select! and #reject!.
* #slice! returns rest of hash, not slice of hash like following. It may be confusing.

hash = {1=>2,3=>4,5=>6}
hash.slice!(1,3) #=> {5,6}
hash #=> {1=>2,3=>4}
----------------------------------------
Feature #8499: Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
https://bugs.ruby-lang.org/issues/8499#change-40745

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:60296] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (19 preceding siblings ...)
  2013-07-29  3:24 ` [ruby-core:56252] " Glass_saga (Masaki Matsushita)
@ 2014-01-30  6:17 ` shibata.hiroshi
  2014-06-22 15:14 ` [ruby-core:63275] " nobu
                   ` (5 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: shibata.hiroshi @ 2014-01-30  6:17 UTC (permalink / raw
  To: ruby-core

Issue #8499 has been updated by Hiroshi SHIBATA.

Target version changed from 2.1.0 to current: 2.2.0

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

* Author: Kenta Murata
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category: core
* Target version: current: 2.2.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

---Files--------------------------------
patch.diff (4.05 KB)
patch2.diff (4.07 KB)


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

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:63275] [ruby-trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (20 preceding siblings ...)
  2014-01-30  6:17 ` [ruby-core:60296] " shibata.hiroshi
@ 2014-06-22 15:14 ` nobu
  2015-11-07 20:17 ` [ruby-core:71381] [Ruby trunk " keithrbennett
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: nobu @ 2014-06-22 15:14 UTC (permalink / raw
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:71381] [Ruby trunk - Feature #8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (21 preceding siblings ...)
  2014-06-22 15:14 ` [ruby-core:63275] " nobu
@ 2015-11-07 20:17 ` keithrbennett
  2017-09-07 10:26 ` [ruby-core:82698] [Ruby trunk Feature#8499] " glass.saga
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: keithrbennett @ 2015-11-07 20:17 UTC (permalink / raw
  To: ruby-core

Issue #8499 has been updated by Keith Bennett.


I was about to report this feature request but was happy to find that it was already there...but disappointed that it's been here so long. I'm using Ruby but not Rails and have been needing this functionality a lot lately.

Unless I'm misunderstanding, the implementation of such methods would be trivial.  I would much rather see this implemented with a nonoptimal name than not implemented at all.

'slice' and 'except' are ok with me, but if there is a concern about their correctness as names, perhaps they could be 'select_if_key_in' and 'reject_if_key_in'.

But again, anything would be better than nothing.

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

* Author: Kenta Murata
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:82698] [Ruby trunk Feature#8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (22 preceding siblings ...)
  2015-11-07 20:17 ` [ruby-core:71381] [Ruby trunk " keithrbennett
@ 2017-09-07 10:26 ` glass.saga
  2017-09-19  5:42 ` [ruby-core:82860] " glass.saga
                   ` (2 subsequent siblings)
  26 siblings, 0 replies; 30+ messages in thread
From: glass.saga @ 2017-09-07 10:26 UTC (permalink / raw
  To: ruby-core

Issue #8499 has been updated by Glass_saga (Masaki Matsushita).

File patch3.diff added
Target version set to 2.5

I just rebased it to trunk.

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

* 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)


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

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:82860] [Ruby trunk Feature#8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (23 preceding siblings ...)
  2017-09-07 10:26 ` [ruby-core:82698] [Ruby trunk Feature#8499] " glass.saga
@ 2017-09-19  5:42 ` glass.saga
  2017-10-19  7:28 ` [ruby-core:83381] " knu
  2017-10-19  7:48 ` [ruby-core:83382] [Ruby trunk Feature#8499][Closed] " muraken
  26 siblings, 0 replies; 30+ messages in thread
From: glass.saga @ 2017-09-19  5:42 UTC (permalink / raw
  To: ruby-core

Issue #8499 has been updated by Glass_saga (Masaki Matsushita).

File patch4.diff added

Improved implementation and test.
Added documentation.

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

* 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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:83381] [Ruby trunk Feature#8499] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (24 preceding siblings ...)
  2017-09-19  5:42 ` [ruby-core:82860] " glass.saga
@ 2017-10-19  7:28 ` knu
  2017-10-19  7:48 ` [ruby-core:83382] [Ruby trunk Feature#8499][Closed] " muraken
  26 siblings, 0 replies; 30+ messages in thread
From: knu @ 2017-10-19  7:28 UTC (permalink / raw
  To: 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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [ruby-core:83382] [Ruby trunk Feature#8499][Closed] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport
  2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
                   ` (25 preceding siblings ...)
  2017-10-19  7:28 ` [ruby-core:83381] " knu
@ 2017-10-19  7:48 ` muraken
  26 siblings, 0 replies; 30+ messages in thread
From: muraken @ 2017-10-19  7:48 UTC (permalink / raw
  To: ruby-core

Issue #8499 has been updated by mrkn (Kenta Murata).

Status changed from Assigned to Closed

As `Hash#slice` has been accepted in #13563, I decided to close this issue.
I intend to open the different issue for discussing other methods such as `Hash#except`.

Thanks.

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

* Author: mrkn (Kenta Murata)
* Status: Closed
* 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/

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2017-10-19  7:48 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06  7:12 [ruby-core:55330] [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#except! from ActiveSupport mrkn (Kenta Murata)
2013-06-06  7:13 ` [ruby-core:55331] [ruby-trunk - Feature #8499] " sorah (Shota Fukumori)
2013-06-06  7:21 ` [ruby-core:55332] Re: [ruby-trunk - Feature #8499][Assigned] " Zachary Scott
2013-06-06  7:27 ` [ruby-core:55333] [ruby-trunk - Feature #8499] " nobu (Nobuyoshi Nakada)
2013-06-06  7:28 ` [ruby-core:55334] " mrkn (Kenta Murata)
2013-06-06  7:51 ` [ruby-core:55335] " mrkn (Kenta Murata)
2013-06-06  7:59 ` [ruby-core:55336] " nobu (Nobuyoshi Nakada)
2013-06-06  8:10 ` [ruby-core:55338] " mrkn (Kenta Murata)
2013-06-06  8:20 ` [ruby-core:55339] " charliesome (Charlie Somerville)
2013-06-06 13:43 ` [ruby-core:55342] " nobu (Nobuyoshi Nakada)
2013-06-06 13:45 ` [ruby-core:55343] " rosenfeld (Rodrigo Rosenfeld Rosas)
2013-06-06 15:15 ` [ruby-core:55344] " prijutme4ty (Ilya Vorontsov)
2013-06-06 15:35   ` [ruby-core:55345] " Clay Trump
2013-06-06 15:38 ` [ruby-core:55346] " mrkn (Kenta Murata)
2013-06-06 16:50   ` [ruby-core:55347] Re: [ruby-trunk - Feature #8499][Assigned] " Zachary Scott
2013-06-06 18:22 ` [ruby-core:55348] [ruby-trunk - Feature #8499] " vipulnsward (Vipul Amler)
2013-06-07  1:37 ` [ruby-core:55352] " nobu (Nobuyoshi Nakada)
2013-07-26 13:58 ` [ruby-core:56205] " Glass_saga (Masaki Matsushita)
2013-07-27  6:22 ` [ruby-core:56220] " matz (Yukihiro Matsumoto)
2013-07-27  6:25 ` [ruby-core:56221] " znz (Kazuhiro NISHIYAMA)
2013-07-27 20:56 ` [ruby-core:56235] " nobu (Nobuyoshi Nakada)
2013-07-28  9:26 ` [ruby-core:56242] " mrkn (Kenta Murata)
2013-07-29  3:24 ` [ruby-core:56252] " Glass_saga (Masaki Matsushita)
2014-01-30  6:17 ` [ruby-core:60296] " shibata.hiroshi
2014-06-22 15:14 ` [ruby-core:63275] " nobu
2015-11-07 20:17 ` [ruby-core:71381] [Ruby trunk " keithrbennett
2017-09-07 10:26 ` [ruby-core:82698] [Ruby trunk Feature#8499] " glass.saga
2017-09-19  5:42 ` [ruby-core:82860] " glass.saga
2017-10-19  7:28 ` [ruby-core:83381] " knu
2017-10-19  7:48 ` [ruby-core:83382] [Ruby trunk Feature#8499][Closed] " muraken

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).