call to_hash before replacing hash
implement Hash#initialize in C
merge test code from #2003