class Hash

Public Instance Methods

to_yaml( opts = {} ) click to toggle source

Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)

Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb

# File lib/jack/ext/hash.rb, line 8
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