add a each_pair to indexed and use in types

This commit is contained in:
Torsten Ruger
2016-12-07 23:35:51 +02:00
parent 266a04040b
commit 2741f35380
5 changed files with 47 additions and 8 deletions

View File

@ -103,8 +103,6 @@ module Parfait
end
def each
# not sure how to do this with define_method, because of the double block issue.
# probably some clever way around that, but not important
index = 1
while index <= self.get_length
item = get(index)
@ -114,6 +112,17 @@ module Parfait
self
end
def each_pair
index = 1
while index <= self.get_length
key = get( index )
value = get(index + 1)
yield key , value
index = index + 2
end
self
end
def set_length len
was = self.get_length
return if was == len

View File

@ -46,6 +46,7 @@ module Parfait
def get_internal_word(index)
@memory[index]
end
# 1 -based index
def set_internal_word(index , value)
raise "failed init for #{self.class}" unless @memory
@ -132,6 +133,7 @@ module Parfait
def instance_variables
get_instance_variables.to_a.collect{ |n| "@#{n}".to_sym }
end
# name comes in as a ruby @var name
def instance_variable_get name
var = get_instance_variable name.to_s[1 .. -1].to_sym

View File

@ -66,10 +66,8 @@ module Parfait
def instance_names
names = List.new
name = true
each do |item|
names.push(item) if name
name = ! name
each_pair do |name , type|
names.push(name)
end
names
end
@ -110,5 +108,8 @@ module Parfait
nil # stop resolve recursing up metaclasses
end
def hash
h = name.hash
end
end
end