Written by Sean Behan on Sun Jun 17th 2012
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}

Tagged with..
#data structures #hash #how to #programming #ruby #yaml #ruby

Just finishing up brewing up some fresh ground comments...