Class: Hash

Inherits:
Object show all
Defined in:
lib/pik/config_file.rb

Direct Known Subclasses

Pik::ConfigFile, Zip::ZipExtraField

Instance Method Summary collapse

Instance Method Details

#to_yaml(opts = {}) ⇒ Object

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



37
38
39
40
41
42
43
44
45
# File 'lib/pik/config_file.rb', line 37

def to_yaml( opts = {} )
  YAML::quick_emit( object_id, opts ) do |out|
    out.map( taguri, to_yaml_style ) do |map|
      sort_by{|s| s[0].to_s}.each do |k, v|   # <-- here's my addition (the 'sort')
        map.add( k, v )
      end
    end
  end
end