简体   繁体   English

数组到键值对(哈希)

[英]Array to key value pair (Hash)

>> description

=> [" name=\"margin-top\" content=\"1\" />\r\n", " name=\"oreintation\" content=\"horizontal\" />\r\n", " name=\"paper-height\" content=\"6\" />\r\n", " name=\"paper-width\" content=\"5\" />\r\n", " name=\"margin-left\" content=\"3\" />\r\n"]

description is of type array descriptionarray类型

I need key as margin-top value 1 . 我需要key作为margin-top1
I need key as oreintation value oreintation and so on, how to get this done? 我需要key作为oreintationoreintation等,如何做到这一点?

Use 采用

result = {}
description.each{|val|
 result[val.split("\"")[1]] = val.split("\"")[3]
}
result # contains expected hash

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

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