On 16/11/2015 2:32 AM, <6ftdan@gmail.com> wrote:
>
> 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.
>
I get the use-case, but I think the understandability of the code starts to suffer.
What about something completely new but splat-like?
hash[*], current = example.call
This is even better when the hash comes last, it looks more like an options parameter:
opts = get_default_hash
a, b, opts[*] = example2.call
I would assume this also works in single assignment:
opts = get_default_hash
opts[*] = get_new_opts