fix weird object bug
This commit is contained in:
parent
a3c9ab7e29
commit
9f292ba618
@ -13,8 +13,7 @@ module Sof
|
||||
|
||||
def add object , level
|
||||
return if is_value?(object)
|
||||
if( @objects.has_key?(object) )
|
||||
occurence = @objects[object]
|
||||
if( occurence = @objects[object] )
|
||||
occurence.level = level if occurence.level > level
|
||||
return
|
||||
end
|
||||
|
@ -48,13 +48,13 @@ module Sof
|
||||
end
|
||||
def out io , level = 0
|
||||
io.write(@data)
|
||||
indent = " " * level
|
||||
indent = " " * (level + 1)
|
||||
@children.each_with_index do |child , i|
|
||||
k , v = child
|
||||
io.write "\n#{indent}"
|
||||
io.write ".."
|
||||
k.out(io , level + 1)
|
||||
v.out(io , level + 1)
|
||||
k.out(io , level + 2)
|
||||
io.write " "
|
||||
v.out(io , level + 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -15,8 +15,8 @@ module Sof
|
||||
end
|
||||
|
||||
def attributes_for object
|
||||
attributes = object.instance_variables.collect{|i| i.to_s[1..-1].to_sym } # chop of @
|
||||
attributes - Volotile.attributes(object.class)
|
||||
atts = object.instance_variables.collect{|i| i.to_s[1..-1].to_sym } # chop of @
|
||||
atts - Volotile.attributes(object.class)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -27,13 +27,13 @@ module Sof
|
||||
|
||||
def object_sof_node( object , level)
|
||||
head = object.class.name + "("
|
||||
attributes = attributes_for(object)
|
||||
immediate , extended = attributes.partition {|a| is_value?(get_value(object , a) ) }
|
||||
atts = attributes_for(object)
|
||||
immediate , extended = atts.partition {|a| is_value?(get_value(object , a) ) }
|
||||
head += immediate.collect {|a| "#{a}: #{get_value(object , a).to_sof()}"}.join(", ") + ")"
|
||||
node = ObjectNode.new(head)
|
||||
extended.each do |a|
|
||||
val = get_value(object , a)
|
||||
node.add( write.to_sof_node(a) , writer.to_sof_node(val) )
|
||||
node.add( to_sof_node(a) , to_sof_node(val) )
|
||||
end
|
||||
node
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ class BasicSof < MiniTest::Test
|
||||
end
|
||||
def test_object_extra_array
|
||||
@out = Sof::Writer.write(ObjectWithAttributes.new.extra_array)
|
||||
check "#{OBJECT_STRING}"
|
||||
check "#{OBJECT_STRING}\n :extra -:sym\n -123"
|
||||
end
|
||||
def test_simple_array
|
||||
@out = Sof::Writer.write([true, 1234])
|
||||
|
Loading…
Reference in New Issue
Block a user