Skip to content

Instantly share code, notes, and snippets.

@hsanjuan
Created January 22, 2013 15:44
Show Gist options
  • Save hsanjuan/4595663 to your computer and use it in GitHub Desktop.
Save hsanjuan/4595663 to your computer and use it in GitHub Desktop.
Ordered YAML generation with Ruby 1.8
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