fix all existing (hash) tests

This commit is contained in:
Torsten Ruger
2014-08-16 15:16:07 +03:00
parent 90e4837b2e
commit 9669831f78
3 changed files with 17 additions and 16 deletions

View File

@ -1,9 +1,12 @@
Hash.class_eval do
def to_sof_node(members , level)
node = Sof::NodeList.new(nil)
node = Sof::NodeList.new()
each do |key , object|
k = key.to_sof() + ": "
v = members.to_sof_node( object )
v.data = "#{k}#{v.data}"
node.add v
end
node
end
end

View File

@ -10,17 +10,18 @@ module Sof
end
class SimpleNode < Node
def initialize head
@head = head
def initialize data
@data = data
end
attr_accessor :head
attr_accessor :data
def out io , level
io.write(head) if head
io.write(data) if data
end
end
class NodeList < Node
class NodeList < SimpleNode
def initialize
super(nil)
@children = []
end
attr_accessor :children
@ -31,6 +32,7 @@ module Sof
end
def out io , level = 0
super
return if @children.empty?
first = @children.first
io.write "-"