Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/bookpress.rb
Overview
This reopens the Hash class to add a method to allow sorting by key recursively
Instance Method Summary collapse
Instance Method Details
#sort_by_key(recursive = false, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/bookpress.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 |