[英]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.