[ruby-trunk - Feature #5735][Open] Extending the use of splat operator to when it is inside a hash

Issue #5735 has been reported by Tsuyoshi Sawada.


Feature #5735: Extending the use of splat operator to when it is inside
a hash

Author: Tsuyoshi Sawada
Status: Open
Priority: Normal
Assignee:
Category:
Target version:

Ruby convention of allowing omittion of the curly brackets for the last
argument is convenient:

foo(arg1, arg2, 1 => :a, 2 => :b)

Sometimes, I want to pass a hash with some modifications. For example,
suppose h = {3 => :c, 4 => :d, 5 => :e} is a hash already defined and
that I want to add some key-value pairs as well as overwrite some values
of h, such as {3 => :c, 4 => :f, 5 => :e, 6 => :g}, and pass that. The
current convention only allows:

foo(arg1, arg2, h.merge(4 => :f, 6 => :g))

but it would be more convenient if a hash preceded by the splat operator
is placed in a hash, it is interpreted as part of the hash, allowing
notations like:

foo(arg1, arg2, *h, 4 => :f, 6 => :g)

or, if I want to overwrite the hash {4 => :f, 6 => :g} with h, then:

foo(arg1, arg2, 4 => :f, 6 => :g, *h)

Or besides the argument position, in general, usages like the following:

{3 => :h, *h, 4 => :f, 6 => :g}

This is an analogy from the splat operator used within an array:

[1, 2, *[4, 5, 6], 7, 8]

Issue #5735 has been updated by mame (Yusuke E.).

Status changed from Open to Feedback
Assignee set to matz (Yukihiro M.)

Marc-Andre proposed a similar idea at [ruby-core:41772], and Matz
commented a little at [ruby-core:41822].
It would be good to investigate how many use cases occur in real world.

matz wrote:

the end, since hashes do not have order.

Yusuke E. [email protected]


Feature #5735: Extending the use of splat operator to when it is inside
a hash

Author: sawa (Tsuyoshi Sawada)
Status: Feedback
Priority: Normal
Assignee: matz (Yukihiro M.)
Category:
Target version:

Ruby convention of allowing omittion of the curly brackets for the last
argument is convenient:

foo(arg1, arg2, 1 => :a, 2 => :b)

Sometimes, I want to pass a hash with some modifications. For example,
suppose h = {3 => :c, 4 => :d, 5 => :e} is a hash already defined and
that I want to add some key-value pairs as well as overwrite some values
of h, such as {3 => :c, 4 => :f, 5 => :e, 6 => :g}, and pass that. The
current convention only allows:

foo(arg1, arg2, h.merge(4 => :f, 6 => :g))

but it would be more convenient if a hash preceded by the splat operator
is placed in a hash, it is interpreted as part of the hash, allowing
notations like:

foo(arg1, arg2, *h, 4 => :f, 6 => :g)

or, if I want to overwrite the hash {4 => :f, 6 => :g} with h, then:

foo(arg1, arg2, 4 => :f, 6 => :g, *h)

Or besides the argument position, in general, usages like the following:

{3 => :h, *h, 4 => :f, 6 => :g}

This is an analogy from the splat operator used within an array:

[1, 2, *[4, 5, 6], 7, 8]

Issue #5735 has been updated by mame (Yusuke E.).

Target version set to next minor


Feature #5735: Extending the use of splat operator to when it is inside
a hash

Author: sawa (Tsuyoshi Sawada)
Status: Feedback
Priority: Normal
Assignee: matz (Yukihiro M.)
Category:
Target version: next minor

Ruby convention of allowing omittion of the curly brackets for the last
argument is convenient:

foo(arg1, arg2, 1 => :a, 2 => :b)

Sometimes, I want to pass a hash with some modifications. For example,
suppose h = {3 => :c, 4 => :d, 5 => :e} is a hash already defined and
that I want to add some key-value pairs as well as overwrite some values
of h, such as {3 => :c, 4 => :f, 5 => :e, 6 => :g}, and pass that. The
current convention only allows:

foo(arg1, arg2, h.merge(4 => :f, 6 => :g))

but it would be more convenient if a hash preceded by the splat operator
is placed in a hash, it is interpreted as part of the hash, allowing
notations like:

foo(arg1, arg2, *h, 4 => :f, 6 => :g)

or, if I want to overwrite the hash {4 => :f, 6 => :g} with h, then:

foo(arg1, arg2, 4 => :f, 6 => :g, *h)

Or besides the argument position, in general, usages like the following:

{3 => :h, *h, 4 => :f, 6 => :g}

This is an analogy from the splat operator used within an array:

[1, 2, *[4, 5, 6], 7, 8]