From: "MartinBosslet (Martin Bosslet)" Date: 2012-03-29T23:42:17+09:00 Subject: [ruby-core:43867] [ruby-trunk - Feature #6219] Return value of Hash#store Issue #6219 has been updated by MartinBosslet (Martin Bosslet). rosenfeld (Rodrigo Rosenfeld Rosas) wrote: > nobu (Nobuyoshi Nakada) wrote: > > And, what should be returned if the key wasn't set? > > Its default value? Seems reasonable to me. To detect whether a key hasn't been set yet, one would check for the presence of the default value. That doesn't catch cases where a key with a default value is actually set, but that seems fine to me. Voices against this? ---------------------------------------- Feature #6219: Return value of Hash#store https://bugs.ruby-lang.org/issues/6219#change-25372 Author: MartinBosslet (Martin Bosslet) Status: Open Priority: Low Assignee: Category: core Target version: 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. -- http://bugs.ruby-lang.org/