Class: Ookie::MemoryArray
- Inherits:
-
String
- Object
- String
- Ookie::MemoryArray
- Defined in:
- lib/ookie/memoryarray.rb
Instance Attribute Summary collapse
-
#maxpointer ⇒ Object
readonly
Returns the value of attribute maxpointer.
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Instance Method Summary collapse
- #+@ ⇒ Object
- #-@ ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ MemoryArray
constructor
A new instance of MemoryArray.
- #next ⇒ Object
- #prev ⇒ Object
- #put(value) ⇒ Object
Constructor Details
#initialize ⇒ MemoryArray
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
#maxpointer ⇒ Object (readonly)
Returns the value of attribute maxpointer.
13 14 15 |
# File 'lib/ookie/memoryarray.rb', line 13 def maxpointer @maxpointer end |
#pointer ⇒ Object (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 |
#get ⇒ Object
38 39 40 |
# File 'lib/ookie/memoryarray.rb', line 38 def get self.getbyte(@pointer) || 0 end |
#next ⇒ Object
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 |
#prev ⇒ Object
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 |