在Ruby中映射哈希键

ste*_*iel 0 ruby hash key

如果我有哈希

{"one"=>1, "two"=>2, "three"=>3}
Run Code Online (Sandbox Code Playgroud)

映射键以获取数组的最佳方法是什么:

["one", "two", "three"]
Run Code Online (Sandbox Code Playgroud)

Ale*_*yne 6

{"one"=>1, "two"=>2, "three"=>3}.keys #=> ["one", "two", "three"]
Run Code Online (Sandbox Code Playgroud)

文档非常适合发现这些问题的答案.

如果问题是"我如何从Y型对象获取X数据?",那么通过对象类型Y的文档阅读应该是你要去的第一个地方.


Arm*_*n H 5

{"one"=>1, "two"=>2, "three"=>3}.keys
Run Code Online (Sandbox Code Playgroud)