move index_of to list

and give it a sort of basic implementation
This commit is contained in:
Torsten Ruger 2015-05-14 19:54:38 +03:00
parent c2b84925a4
commit 5e0e8c8364
2 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,6 @@
# An Object is really a hash like structure. It is dynamic and
# you want to store values by name.
# you want to store values by name (instance variable names).
#
# One could (like mri), store the names in each object, but that is wasteful
# Instead we store only the values, and access them by index.
# The Layout allows the mapping of names to index.
@ -19,15 +20,7 @@
# Together they turn the object into a hash like structure
module Parfait
class Layout < Object
# given a name as symbol, return the integer index of that entry
# we use 0 as "not found" as we don't want negatives, and can't raise
# luckily 0 is always the type-word in an object and so by returning
# one-offsets we can use the return value straight without adding 1
def index_of( name )
#internal implementation....
end
class Layout < List
end
end

View File

@ -3,6 +3,18 @@
module Parfait
class List < Object
def index_of( item )
max = self.length
counter = 0
while( counter < max )
if( internal_object_get(index) == item)
return counter
end
counter = counter + 1
end
return nil
end
# push means add to the end
# this automatically grows the List
def push value