Created
January 6, 2012 17:28
-
-
Save seanbehan/1571559 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'yaml' | |
# Nested YAML structure from something-nested.yml | |
# | |
# nested: | |
# key: value | |
# key_two: value_two | |
# Procedural Approach to building a single Hash from nested YAML data structure. | |
@yaml = YAML.load_file("something-nested.yml") | |
@container = {} | |
@yaml.values.each do |value| | |
@container.merge!(value) | |
end | |
@container.inspect | |
# => {:key => value, :key_two => value_two} | |
# And a one liner... | |
@yaml.values.inject({}) { |container, value| container.merge(value) } | |
# => {:key => value, :key_two => value_two} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment