We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c3a5ba0 commit ba5e3f6Copy full SHA for ba5e3f6
json2yaml
@@ -26,6 +26,24 @@ require "bundler/setup"
26
require 'json'
27
require 'yaml'
28
29
+class Hash
30
+ # Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)
31
+ #
32
+ # Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
33
34
+ # Credit goes to Dov Murik http://snippets.dzone.com/user/dubek
35
36
+ def to_yaml( opts = {} )
37
+ YAML::quick_emit( object_id, opts ) do |out|
38
+ out.map( taguri, to_yaml_style ) do |map|
39
+ sort.each do |k, v| # <-- here's my addition (the 'sort')
40
+ map.add( k, v )
41
+ end
42
43
44
45
+end
46
+
47
raise Exception, 'you must provide a json files' unless ARGV[0]
48
49
my_hash = JSON.parse(File.open(ARGV[0]).read)
0 commit comments