@@ -297,13 +297,13 @@ def merge(*hashes, &block)
297
297
# hash['a'] = nil
298
298
# hash.reverse_merge(a: 0, b: 1) # => {"a"=>nil, "b"=>1}
299
299
def reverse_merge ( other_hash )
300
- super ( self . class . new ( other_hash ) )
300
+ super ( cast ( other_hash ) )
301
301
end
302
302
alias_method :with_defaults , :reverse_merge
303
303
304
304
# Same semantics as +reverse_merge+ but modifies the receiver in-place.
305
305
def reverse_merge! ( other_hash )
306
- super ( self . class . new ( other_hash ) )
306
+ super ( cast ( other_hash ) )
307
307
end
308
308
alias_method :with_defaults! , :reverse_merge!
309
309
@@ -312,7 +312,7 @@ def reverse_merge!(other_hash)
312
312
# h = { "a" => 100, "b" => 200 }
313
313
# h.replace({ "c" => 300, "d" => 400 }) # => {"c"=>300, "d"=>400}
314
314
def replace ( other_hash )
315
- super ( self . class . new ( other_hash ) )
315
+ super ( cast ( other_hash ) )
316
316
end
317
317
318
318
# Removes the specified key from the hash.
@@ -406,6 +406,10 @@ def to_proc
406
406
end
407
407
408
408
private
409
+ def cast ( other )
410
+ self . class === other ? other : self . class . new ( other )
411
+ end
412
+
409
413
def convert_key ( key )
410
414
Symbol === key ? key . name : key
411
415
end
0 commit comments