Class: Ookie::MemoryArray

Inherits:
String
  • Object
show all
Defined in:
lib/ookie/memoryarray.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemoryArray

Returns a new instance of MemoryArray.



15
16
17
18
19
# File 'lib/ookie/memoryarray.rb', line 15

def initialize
  @maxpointer = @pointer = 0
  self.<< 0
  super
end

Instance Attribute Details

#maxpointerObject (readonly)

Returns the value of attribute maxpointer.



13
14
15
# File 'lib/ookie/memoryarray.rb', line 13

def maxpointer
  @maxpointer
end

#pointerObject (readonly)

Returns the value of attribute pointer.



13
14
15
# File 'lib/ookie/memoryarray.rb', line 13

def pointer
  @pointer
end

Instance Method Details

#+@Object



47
48
49
# File 'lib/ookie/memoryarray.rb', line 47

def +@
  put(get + 1)
end

#-@Object



51
52
53
# File 'lib/ookie/memoryarray.rb', line 51

def -@
  put(get - 1)
end

#getObject



38
39
40
# File 'lib/ookie/memoryarray.rb', line 38

def get
  self.getbyte(@pointer) || 0
end

#nextObject



21
22
23
24
25
26
27
# File 'lib/ookie/memoryarray.rb', line 21

def next
  if @pointer == @maxpointer
    self.<< 0
    @maxpointer += 1
  end
  @pointer += 1
end

#prevObject



29
30
31
# File 'lib/ookie/memoryarray.rb', line 29

def prev
  @pointer -= 1 unless @pointer == 0
end

#put(value) ⇒ Object



42
43
44
45
# File 'lib/ookie/memoryarray.rb', line 42

def put(value)
  value = value.ord if value.respond_to? :ord	# make Ruby 1.9 happy
  self.setbyte(@pointer, value || 0)
end