adds simple hash and test
This commit is contained in:
parent
2d6a43cf0e
commit
16261f96b0
@ -3,6 +3,7 @@ require_relative "members"
|
||||
require_relative "volotile"
|
||||
require_relative "writer"
|
||||
require_relative "array"
|
||||
require_relative "hash"
|
||||
require_relative "occurence"
|
||||
|
||||
Symbol.class_eval do
|
||||
|
13
lib/sof/hash.rb
Normal file
13
lib/sof/hash.rb
Normal file
@ -0,0 +1,13 @@
|
||||
Hash.class_eval do
|
||||
def to_sof(io , members , level)
|
||||
each_with_index do |pair , i|
|
||||
key , object = pair
|
||||
io.write(" " * level) unless i == 0
|
||||
io.write "-"
|
||||
members.output( io , key)
|
||||
io.write( " " )
|
||||
members.output( io , object)
|
||||
io.write("\n")
|
||||
end
|
||||
end
|
||||
end
|
@ -41,5 +41,9 @@ class BasicSof < MiniTest::Test
|
||||
out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
|
||||
assert_equal "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}\n\n\n" , out
|
||||
end
|
||||
|
||||
def test_simple_hash
|
||||
out = Sof::Writer.write({ one: 1 , tru: true })
|
||||
puts out
|
||||
assert_equal "-:one 1\n-:tru true\n" , out
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user