ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Tsuyoshi Sawada <sawadatsuyoshi@gmail•com>
To: ruby-dev@ruby-lang.org (ruby developers list)
Subject: [ruby-dev:44962] [ruby-trunk - Feature #5735][Open] Extending the use of splat operator to when it is inside a hash
Date: Fri, 9 Dec 2011 13:31:03 +0900	[thread overview]
Message-ID: <redmine.issue-5735.20111209133102@ruby-lang.org> (raw)


Issue #5735 has been reported by Tsuyoshi Sawada.

----------------------------------------
Feature #5735: Extending the use of splat operator to when it is inside a hash
http://redmine.ruby-lang.org/issues/5735

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]




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

             reply	other threads:[~2011-12-09  4:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-09  4:31 Tsuyoshi Sawada [this message]
2012-03-28 15:57 ` [ruby-dev:45452] [ruby-trunk - Feature #5735][Feedback] Extending the use of splat operator to when it is inside a hash mame (Yusuke Endoh)
2012-11-20 12:57 ` [ruby-dev:46561] [ruby-trunk - Feature #5735] " mame (Yusuke Endoh)
2019-07-08  9:53 ` [ruby-dev:50811] [Ruby master Feature#5735] " sawadatsuyoshi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-5735.20111209133102@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).