Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
A. 以String为key的重复key
irb(main):001:0> myHash = {'a' => 'a', 'a' => 'a'} (irb):1: warning: key "a" is duplicated and overwritten on line 1
B. 以数组为键的重复键
irb(main):001:0> myHash = {[1,2,3] => [1,2,3], [1,2,3] => [4,5,6]} => {[1, 2, 3]=>[4, 5, 6]}
对于作为键的重复字符串,不会引发错误,而是警告。
在这两种情况下,重复键都被覆盖为一个,因为这里的返回值是 {"a"=>"a"} 和 {[1, 2, 3]=>[4, 5, 6]}。