mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user