fruit = ["apple","red","banana","yellow"]
=> ["apple", "red", "banana", "yellow"]
Hash[*fruit]
=> {"apple"=>"red", "banana"=>"yellow"}
为什么 splat 会导致数组被如此整齐地解析为 Hash?
或者,更准确地说,哈希是如何“知道”“apple”是键而“red”是其对应的值?
仅仅是因为它们在水果数组中的连续位置吗?
在这里使用 splat 是否重要?哈希不能直接从数组中定义自己吗?