Sha256: 5822dd7589f4658c7a36ca558db4f7275922cbaa9e36c8c500cb0a52b814d8cf

Contents?: true

Size: 500 Bytes

Versions: 30

Compression:

Stored size: 500 Bytes

Contents

# http://www.dzone.com/snippets/generating-yaml-hashes-sorted

require 'yaml' 
class Hash
  # 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
  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
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
jack-eb-1.4.4 lib/jack/ext/hash.rb
jack-eb-1.4.3 lib/jack/ext/hash.rb
jack-eb-1.4.2 lib/jack/ext/hash.rb
jack-eb-1.4.1 lib/jack/ext/hash.rb
jack-eb-1.4.0 lib/jack/ext/hash.rb
jack-eb-1.3.0 lib/jack/ext/hash.rb
jack-eb-1.2.1 lib/jack/ext/hash.rb
jack-eb-1.2.0 lib/jack/ext/hash.rb
jack-eb-1.1.2 lib/jack/ext/hash.rb
jack-eb-1.1.1 lib/jack/ext/hash.rb
jack-eb-1.1.0 lib/jack/ext/hash.rb
jack-eb-1.0.1 lib/jack/ext/hash.rb
jack-eb-1.0.0 lib/jack/ext/hash.rb
jack-eb-0.3.0 lib/jack/ext/hash.rb
jack-eb-0.2.0 lib/jack/ext/hash.rb
jack-eb-0.1.6 lib/jack/ext/hash.rb
jack-eb-0.1.5 lib/jack/ext/hash.rb
jack-eb-0.1.4 lib/jack/ext/hash.rb
jack-eb-0.1.3 lib/jack/ext/hash.rb
jack-eb-0.1.2 lib/jack/ext/hash.rb