[英]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
description
是array
类型
I need key
as margin-top
value 1
. 我需要
key
作为margin-top
值1
。
I need key
as oreintation
value oreintation
and so on, how to get this done? 我需要
key
作为oreintation
值oreintation
等,如何做到这一点?
Use 采用
result = {}
description.each{|val|
result[val.split("\"")[1]] = val.split("\"")[3]
}
result # contains expected hash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.