ruby on rails - 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 of type array
i need key margin-top value 1.
need key oreintation value oreintation , on, how done?
use
result = {} description.each{|val| result[val.split("\"")[1]] = val.split("\"")[3] } result # contains expected hash
Comments
Post a Comment