Created
March 26, 2014 11:17
-
-
Save adammcarth/9781067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ostruct" | |
# Actual value obtained from elsewhere, must | |
# be in this format up until now. | |
required_records = {"1" => { "name" => "Adam" }, "2" => { "name" => "John" }} | |
# Loop through each required record and | |
# assemble each key-value into the open structure output. | |
output = Array.new | |
required_records.each do |id, record| | |
output += OpenStruct.new({ "id" => id.to_i }.merge(record)) | |
end | |
# Real output => can't convert open struct to array | |
# Desired output => [#<OpenStruct id=1, name="Adam">, #<OpenStruct id=2, name="John">] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment