Project

General

Profile

Actions

Feature #6219

closed

Return value of Hash#store

Added by MartinBosslet (Martin Bosslet) almost 12 years ago. Updated over 3 years ago.

Status:
Feedback
Target version:
-
[ruby-core:43814]

Description

Hash#store returns the value that was just assigned, for example:

h[:a] = b # => b

Does anyone rely on this behavior, are there cases when this becomes handy?

If however the return value is discarded most of the time, I was thinking it
might be beneficial if we would return the previous value of a given key (nil if
none was assigned yet) instead. That way we could assign and check for a collision
in one pass, something that right now can only be done in two separate steps.


Files

0001-Hash-store-return-old-value.patch (6.8 KB) 0001-Hash-store-return-old-value.patch nobu (Nobuyoshi Nakada), 03/30/2012 01:09 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0