diff --git a/.gitignore b/.gitignore index c1e0daf..f979985 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ rdoc pkg ## PROJECT::SPECIFIC +.rvmrc diff --git a/lib/ap/awesome_print.rb b/lib/ap/awesome_print.rb index 604d0d3..7d61f14 100755 --- a/lib/ap/awesome_print.rb +++ b/lib/ap/awesome_print.rb @@ -75,7 +75,8 @@ class AwesomePrint def awesome_hash(h) return "{}" if h == {} - data = h.keys.map do |key| + keys = @options[:sorted_hash_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys + data = keys.map do |key| plain_single_line do [ awesome(key), h[key] ] end diff --git a/spec/awesome_print_spec.rb b/spec/awesome_print_spec.rb index 57109e3..0c90745 100644 --- a/spec/awesome_print_spec.rb +++ b/spec/awesome_print_spec.rb @@ -263,6 +263,36 @@ EOS end end + #------------------------------------------------------------------------------ + describe "Hash with several keys" do + before(:each) do + @hash = {"b" => "b", :a => "a", :z => "z", "alpha" => "alpha"} + end + + it "plain multiline" do + @hash.ai(:plain => true).should == <<-EOS.strip +{ + "b" => "b", + :a => "a", + :z => "z", + "alpha" => "alpha" +} +EOS + end + + it "plain multiline with sorted keys" do + @hash.ai(:plain => true, :sorted_hash_keys => true).should == <<-EOS.strip +{ + :a => "a", + "alpha" => "alpha", + "b" => "b", + :z => "z" +} +EOS + end + + end + #------------------------------------------------------------------------------ describe "Negative options[:indent]" do before(:each) do