From: 6ftdan@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:71519] [Ruby trunk - Feature #11690] Update Hash during multiple assignment
Date: Tue, 17 Nov 2015 11:41:08 +0000 [thread overview]
Message-ID: <redmine.journal-54895.20151117114105.cfd5a4ef44424414@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11690.20151115163053@ruby-lang.org
Issue #11690 has been updated by Daniel P. Clark.
You're right! I misspelled it. If I had added a space "in jest" it would be a joke. `ingest` is what I had meant to say.
----------------------------------------
Feature #11690: Update Hash during multiple assignment
https://bugs.ruby-lang.org/issues/11690#change-54895
* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Given that we can assign multiple variables at once
~~~ruby
a,b,c = 1,2,3
~~~
It would be nice to be able to update a Hash during multiple assignment rather than replacing it. Currently
~~~ruby
x = {a: 1, b: 2}
x, y ,z = {c: 3}, 6, 7
x
# => {c: 3}
~~~
What I propose is adding `Hash#update=` to permit updating during multiple assignment.
~~~ruby
class Hash
def update=(h)
update(h)
end
end
x = {a: 1, b: 2}
x.update, y ,z = {c: 3}, 6, 7
x
# => {a: 1, b: 2, c: 3}
~~~
This would be most useful in scenarios where a method or proc return multiple values. When the method returns the values we don't normally know the key outside where the hash assignment is.
~~~ruby
example = proc { [{:hi => :hello}, 5] }
hash = {}
# Currently in Ruby with an Unknown key multiple assignment isn't an option
hash[????], current = example.call
# We currently have to two step it
result, current = example.call
hash.update(result)
~~~
But with `Hash#update=` we don't have to know the key.
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2015-11-17 11:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11690.20151115163053@ruby-lang.org>
2015-11-15 16:30 ` [ruby-core:71495] [Ruby trunk - Feature #11690] [Open] Update Hash during multiple assignment 6ftdan
2015-11-15 21:04 ` [ruby-core:71499] " Matthew Kerwin
2015-11-16 14:17 ` [ruby-core:71507] [Ruby trunk - Feature #11690] " 6ftdan
2015-11-16 21:31 ` [ruby-core:71508] " Matthew Kerwin
2015-11-17 1:29 ` [ruby-core:71509] " nobu
2015-11-17 2:10 ` [ruby-core:71510] " 6ftdan
2015-11-17 3:06 ` [ruby-core:71514] " nobu
2015-11-17 11:41 ` 6ftdan [this message]
2015-11-18 18:41 ` [ruby-core:71562] " 6ftdan
2015-11-18 19:13 ` [ruby-core:71563] " 6ftdan
2015-11-22 23:29 ` [ruby-core:71635] " 6ftdan
2015-12-10 12:26 ` [ruby-core:72030] " 6ftdan
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.journal-54895.20151117114105.cfd5a4ef44424414@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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).