From: "MartinBosslet (Martin Bosslet)" Date: 2012-03-29T06:40:55+09:00 Subject: [ruby-core:43819] [ruby-trunk - Feature #6219] Return value of Hash#store Issue #6219 has been updated by MartinBosslet (Martin Bosslet). Right, good point. OK, then let me rephrase it for explicitly calling store. What I would prefer is: h = { a: 1 } h.store(:a, 2) # => 1 h.store(:b, 3) # => nil That way I can check for collisions in one pass without having to call has_key? first. Otherwise the result is evaluating the internal hash function twice, once for has_key? and once for the following call to store. ---------------------------------------- Feature #6219: Return value of Hash#store https://bugs.ruby-lang.org/issues/6219#change-25323 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/