From fc9615a649c2ed7a8f47db1e5f2977f4cd230a86 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 27 Aug 2014 14:46:34 +0300 Subject: [PATCH] short hash, inline like for array. with curly braces off course --- lib/sof/hash.rb | 10 +++++++++- test/sof.rb | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/sof/hash.rb b/lib/sof/hash.rb index 101b5db3..ad3c4aa9 100644 --- a/lib/sof/hash.rb +++ b/lib/sof/hash.rb @@ -22,7 +22,15 @@ module Sof end end def short_out(io,level) - long_out(io,level) + io.write("{") + children.each_with_index do |child , i| + key , val = child + key.out(io , level + 1) + io.write " => " + val.out(io , level + 1) + io.write ", " unless (i+1) == children.length + end + io.write("}") end def long_out io , level indent = " " * level diff --git a/test/sof.rb b/test/sof.rb index c8fe1a2d..b1fa2647 100644 --- a/test/sof.rb +++ b/test/sof.rb @@ -60,7 +60,7 @@ class BasicSof < MiniTest::Test end def test_simple_hash @out = Sof::Writer.write({ one: 1 , tru: true }) - check "-:one => 1\n-:tru => true" + check "{:one => 1, :tru => true}" end def test_hash_object @out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new }) @@ -68,7 +68,7 @@ class BasicSof < MiniTest::Test end def test_array_hash @out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }]) - check "-true\n-1\n--:one => 1\n -:tru => true" + check "-true\n-1\n-{:one => 1, :tru => true}" end def test_hash_array @out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true })