Module: OSGi::Dependencies::SortedHash

Defined in:
lib/buildr4osgi/osgi/dependencies.rb

Overview

Copy/pasted from here: snippets.dzone.com/posts/show/5811 no author information though.

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



79
80
81
82
83
84
85
86
87
# File 'lib/buildr4osgi/osgi/dependencies.rb', line 79

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