Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/openstudio-standards/utilities/hash.rb,
lib/openstudio-standards/standards/necb/necb_2011/data/standards_data.rb
Overview
monkey patch for recursive hash sorting.
Instance Method Summary collapse
Instance Method Details
#dig(*path) ⇒ Object
4 5 6 7 8 |
# 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) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/openstudio-standards/standards/necb/necb_2011/data/standards_data.rb', line 9 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 |