to_s for parfait list
This commit is contained in:
parent
e430701645
commit
0ebb8e31c6
@ -20,7 +20,7 @@ module Parfait
|
|||||||
super
|
super
|
||||||
self.indexed_length = 0
|
self.indexed_length = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def data_length
|
def data_length
|
||||||
self.class.data_length
|
self.class.data_length
|
||||||
end
|
end
|
||||||
@ -253,6 +253,15 @@ module Parfait
|
|||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
res = "["
|
||||||
|
each do |item|
|
||||||
|
res = res + item.to_s
|
||||||
|
res = res + " ,"
|
||||||
|
end
|
||||||
|
res = res + " ]"
|
||||||
|
return res
|
||||||
|
end
|
||||||
def to_a
|
def to_a
|
||||||
array = []
|
array = []
|
||||||
index = 0
|
index = 0
|
||||||
|
@ -153,7 +153,7 @@ module Parfait
|
|||||||
|
|
||||||
# resolve according to normal oo logic, ie look up in superclass if not present
|
# 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
|
# 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)
|
# 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)
|
# 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
|
# But for now we walk up, as it should really just be to object
|
||||||
|
@ -70,6 +70,9 @@ module Parfait
|
|||||||
end
|
end
|
||||||
assert_equal 2 , counter
|
assert_equal 2 , counter
|
||||||
end
|
end
|
||||||
|
def test_to_s
|
||||||
|
assert_equal "[one ,two ,three , ]" , @list.to_s
|
||||||
|
end
|
||||||
def test_to_a
|
def test_to_a
|
||||||
arr = @list.to_a
|
arr = @list.to_a
|
||||||
assert_equal Array , arr.class
|
assert_equal Array , arr.class
|
||||||
|
Loading…
x
Reference in New Issue
Block a user