Class: RBF::Interpreter::Storage
- Inherits:
-
Hash
- Object
- Hash
- RBF::Interpreter::Storage
- Defined in:
- lib/rbf/interpreter/storage.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #backward! ⇒ Object
- #check! ⇒ Object
- #clear! ⇒ Object
- #decrease! ⇒ Object
- #forward! ⇒ Object
- #get(position = nil) ⇒ Object
- #increase! ⇒ Object
-
#initialize(data) ⇒ Storage
constructor
A new instance of Storage.
- #inspect ⇒ Object
- #reset! ⇒ Object
- #set(value, position = nil) ⇒ Object
Constructor Details
#initialize(data) ⇒ Storage
Returns a new instance of Storage.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rbf/interpreter/storage.rb', line 18 def initialize (data) if data.is_a?(Array) parent = {} data.each_with_index {|value, index| parent[index] = value } super(parent) else super end @position = 0 end |
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
16 17 18 |
# File 'lib/rbf/interpreter/storage.rb', line 16 def position @position end |
Instance Method Details
#backward! ⇒ Object
44 45 46 |
# File 'lib/rbf/interpreter/storage.rb', line 44 def backward! @position -= 1 end |
#check! ⇒ Object
34 35 36 37 38 |
# File 'lib/rbf/interpreter/storage.rb', line 34 def check! unless self[@position].is_a?(Integer) self[@position] = 0 end end |
#clear! ⇒ Object
68 69 70 |
# File 'lib/rbf/interpreter/storage.rb', line 68 def clear! self.clear end |
#decrease! ⇒ Object
54 55 56 57 58 |
# File 'lib/rbf/interpreter/storage.rb', line 54 def decrease! check! self[@position] -= 1 end |
#forward! ⇒ Object
40 41 42 |
# File 'lib/rbf/interpreter/storage.rb', line 40 def forward! @position += 1 end |
#get(position = nil) ⇒ Object
64 65 66 |
# File 'lib/rbf/interpreter/storage.rb', line 64 def get (position=nil) self[position ? position.to_i : @position.to_i].to_i rescue 0 end |
#increase! ⇒ Object
48 49 50 51 52 |
# File 'lib/rbf/interpreter/storage.rb', line 48 def increase! check! self[@position] += 1 end |
#inspect ⇒ Object
77 78 79 |
# File 'lib/rbf/interpreter/storage.rb', line 77 def inspect "#<Storage(#{position}): #{super}>" end |
#reset! ⇒ Object
72 73 74 75 |
# File 'lib/rbf/interpreter/storage.rb', line 72 def reset! clear! @position = 0 end |
#set(value, position = nil) ⇒ Object
60 61 62 |
# File 'lib/rbf/interpreter/storage.rb', line 60 def set (value, position=nil) self[position ? position.to_i : @position.to_i] = value.ord end |