Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/clouds.rb
Overview
shamelessly copied from www.dzone.com/snippets/generating-yaml-hashes-sorted
Instance Method Summary collapse
-
#to_yaml(opts = {}) ⇒ Object
Replacing the to_yaml function so it’ll serialize hashes sorted (by their keys).
Instance Method Details
#to_yaml(opts = {}) ⇒ Object
Replacing the to_yaml function so it’ll serialize hashes sorted (by their keys)
12 13 14 15 16 17 18 19 20 |
# File 'lib/clouds.rb', line 12 def to_yaml( opts = {} ) YAML::quick_emit( object_id, opts ) do |out| out.map( taguri, to_yaml_style ) do |map| sort.each do |k, v| # <-- here's my addition (the 'sort') map.add( k, v ) end end end end |