Forum: Ruby-core [ruby-trunk - Feature #8499][Assigned] Importing Hash#slice, Hash#slice!, Hash#except, and Hash#exce

7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-06 09:13
(Received via mailing list)
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
B99311b48290f8ee37311890a8edfb1d?d=identicon&s=25 sorah (Shota Fukumori) (Guest)
on 2013-06-06 09:14
(Received via mailing list)
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
7fe945668a4fc098e886e20dea71d2ee?d=identicon&s=25 Zachary Scott (Guest)
on 2013-06-06 09:23
(Received via mailing list)
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
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-06-06 09:28
(Received via mailing list)
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
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-06 09:29
(Received via mailing list)
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
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-06 09:52
(Received via mailing list)
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
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-06-06 10:00
(Received via mailing list)
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
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-06 10:10
(Received via mailing list)
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
F736999f7c1b7a87a100faa112bbc0f3?d=identicon&s=25 charliesome (Charlie Somerville) (Guest)
on 2013-06-06 10:21
(Received via mailing list)
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
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-06-06 15:43
(Received via mailing list)
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
2abdb50caf0dc5b510330f68b02db8e4?d=identicon&s=25 rosenfeld (Rodrigo Rosenfeld Rosas) (Guest)
on 2013-06-06 15:47
(Received via mailing list)
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
Fe1c0797f345249625590d25a51efd0a?d=identicon&s=25 prijutme4ty (Ilya Vorontsov) (Guest)
on 2013-06-06 17:15
(Received via mailing list)
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
D52dede4fd700b94aa4c5ffe33e253e7?d=identicon&s=25 Clay Trump (Guest)
on 2013-06-06 17:36
(Received via mailing list)
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.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-06 17:38
(Received via mailing list)
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
F459742822cf8347e83d5c445378a934?d=identicon&s=25 vipulnsward (Vipul Amler) (Guest)
on 2013-06-06 20:22
(Received via mailing list)
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
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-06-07 03:38
(Received via mailing list)
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
C042517d59bed4761cc88681bf71fca8?d=identicon&s=25 Glass_saga (Masaki Matsushita) (Guest)
on 2013-07-26 15:58
(Received via mailing list)
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
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2013-07-27 08:23
(Received via mailing list)
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
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 znz (Kazuhiro NISHIYAMA) (Guest)
on 2013-07-27 08:26
(Received via mailing list)
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#metho...
=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
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-07-27 22:56
(Received via mailing list)
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
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-07-28 11:26
(Received via mailing list)
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
C042517d59bed4761cc88681bf71fca8?d=identicon&s=25 Glass_saga (Masaki Matsushita) (Guest)
on 2013-07-29 05:25
(Received via mailing list)
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
7fe945668a4fc098e886e20dea71d2ee?d=identicon&s=25 Zachary Scott (Guest)
on 2014-01-14 23:12
(Received via mailing list)
>
Eabad423977cfc6873b8f5df62b848a6?d=identicon&s=25 unknown (Guest)
on 2014-01-30 07:24
(Received via mailing list)
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)
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2014-06-22 17:15
(Received via mailing list)
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)
This topic is locked and can not be replied to.