简体   繁体   English

如何获取哈希并转换为数组

[英]how to take a hash and turn into an array

I want to be able to take the following: 我希望能够采取以下措施:

{"6"=>"", "7"=>"104", "8"=>"", "9"=>"", "0"=>"Testing", "2"=>"1", "3"=>"", "10"=>"Testing", "4"=>"1", "5"=>""}

and convert it into 并将其转换为

[["","104","","","Testing"........], ["" ......]

Thank you 谢谢

The Hash class has the method values which returns an array of all the values. 哈希类有该方法values返回所有值的数组。

my_hash = {"6" => "", "7" => "104"}
my_array_of_values = my_hash.values # ["", "104"]

In Ruby, the Hash contains key/value pairs (eg. { key => value }). 在Ruby中,Hash包含键/值对(例如。{key => value})。 The keys method returns an array of the keys and the values method returns an array of the values. keys方法返回keys的数组, values方法返回values的数组。

Read more about the values method here: http://ruby-doc.org/core/classes/Hash.html#M002867 在此处阅读有关值方法的更多信息: http//ruby-doc.org/core/classes/Hash.html#M002867

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM