mruby-hash-ext/hash.rb: make transform_keys! to keep old keys

```ruby
h={1=>2,2=>3}
h.transform_keys!{_1.succ}
```

used to make `h` to `{2=>2}` (duplicated keys were squashed), but now
makes it `{2=>2,3=>3}`.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-12-14 07:39:10 +09:00
parent ba3541bbc4
commit d6dc9caa02
+2 -6
View File
@@ -428,12 +428,8 @@ class Hash
#
def transform_keys!(&block)
return to_enum :transform_keys! unless block
self.keys.each do |k|
value = self[k]
self.__delete(k)
k = block.call(k) if block
self[k] = value
end
hash = self.transform_keys(&block)
self.replace(hash)
self
end
##