Created
January 22, 2013 15:44
-
-
Save hsanjuan/4595663 to your computer and use it in GitHub Desktop.
Ordered YAML generation with Ruby 1.8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def to_yaml(opts={}) | |
YAML::quick_emit( self, opts ) do |out| | |
out.map( taguri, to_yaml_style ) do |map| | |
keys = keys().sort {|a,b| a.to_s <=> b.to_s} | |
keys.each do |k| | |
v = self[k] | |
map.add( k, v ) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment