From: "MartinBosslet (Martin Bosslet)" Date: 2012-03-30T07:48:42+09:00 Subject: [ruby-core:43900] [ruby-trunk - Feature #6219] Return value of Hash#store Issue #6219 has been updated by MartinBosslet (Martin Bosslet). nobu (Nobuyoshi Nakada) wrote: > Calling default proc can be expensive. So I don't think it's good idea to call it always. > A patch to separate Hash#store from Hash#[]=, and let it return the old value. You are right, the default proc is a real "party pooper" here... Could something like Rodrigo proposed work for the default proc case? Did you mean something like it when you proposed separating Hash#store from #[]=, or did you think about something different? ---------------------------------------- Feature #6219: Return value of Hash#store https://bugs.ruby-lang.org/issues/6219#change-25415 Author: MartinBosslet (Martin Bosslet) Status: Assigned Priority: Low Assignee: matz (Yukihiro Matsumoto) Category: core Target version: 3.0 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/