to_s for parfait list

This commit is contained in:
Torsten Ruger 2019-02-17 18:16:19 +02:00
parent e430701645
commit 0ebb8e31c6
3 changed files with 14 additions and 2 deletions

View File

@ -253,6 +253,15 @@ module Parfait
list
end
def to_s
res = "["
each do |item|
res = res + item.to_s
res = res + " ,"
end
res = res + " ]"
return res
end
def to_a
array = []
index = 0

View File

@ -153,7 +153,7 @@ module Parfait
# resolve according to normal oo logic, ie look up in superclass if not present
# NOTE: this will probably not work in future as the code for the superclass
# method, being bound to t adifferent type, will assume that types (not the run-time
# method, being bound to a different type, will assume that types (not the run-time
# actual types) layout. Either need to enforce some c++ style upwards compatibility (buuh)
# or copy the methods and recompile them for the actual type. (maybe still later dynamically)
# But for now we walk up, as it should really just be to object

View File

@ -70,6 +70,9 @@ module Parfait
end
assert_equal 2 , counter
end
def test_to_s
assert_equal "[one ,two ,three , ]" , @list.to_s
end
def test_to_a
arr = @list.to_a
assert_equal Array , arr.class