class Hash

monkey patch for recursive hash sorting.

Add a “dig” method to Hash to check if deeply nested elements exist From: stackoverflow.com/questions/1820451/ruby-style-how-to-check-whether-a-nested-hash-element-exists

Public Instance Methods

dig(*path) click to toggle source
# File lib/openstudio-standards/utilities/hash.rb, line 4
def dig(*path)
  path.inject(self) do |location, key|
    location.respond_to?(:keys) ? location[key] : nil
  end
end
sort_by_key(recursive = false, &block) click to toggle source
# File lib/openstudio-standards/standards/necb/NECB2011/data/standards_data.rb, line 10
def sort_by_key(recursive = false, &block)
  self.keys.sort(&block).reduce({}) do |seed, key|
    seed[key] = self[key]
    if recursive && seed[key].is_a?(Hash)
      seed[key] = seed[key].sort_by_key(true, &block)
    end
    seed
  end
end