move index_of to list
and give it a sort of basic implementation
This commit is contained in:
parent
c2b84925a4
commit
5e0e8c8364
@ -1,5 +1,6 @@
|
|||||||
# An Object is really a hash like structure. It is dynamic and
|
# 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
|
# 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.
|
# Instead we store only the values, and access them by index.
|
||||||
# The Layout allows the mapping of names to index.
|
# The Layout allows the mapping of names to index.
|
||||||
@ -19,15 +20,7 @@
|
|||||||
# Together they turn the object into a hash like structure
|
# Together they turn the object into a hash like structure
|
||||||
|
|
||||||
module Parfait
|
module Parfait
|
||||||
class Layout < Object
|
class Layout < List
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,18 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
class List < Object
|
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
|
# push means add to the end
|
||||||
# this automatically grows the List
|
# this automatically grows the List
|
||||||
def push value
|
def push value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user