Class: BfInterpreter::BfCell
- Inherits:
-
Object
- Object
- BfInterpreter::BfCell
- Defined in:
- lib/yarbf.rb
Instance Attribute Summary collapse
-
#position ⇒ Object
Returns the value of attribute position.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #decrease(decrement = 1, wrap_around = true) ⇒ Object
- #increase(increment = 1, wrap_around = true) ⇒ Object
-
#initialize(position, value = 0) ⇒ BfCell
constructor
A new instance of BfCell.
Constructor Details
#initialize(position, value = 0) ⇒ BfCell
135 136 137 138 |
# File 'lib/yarbf.rb', line 135 def initialize(position, value = 0) @position = position @value = value end |
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
133 134 135 |
# File 'lib/yarbf.rb', line 133 def position @position end |
#value ⇒ Object
Returns the value of attribute value.
133 134 135 |
# File 'lib/yarbf.rb', line 133 def value @value end |
Instance Method Details
#decrease(decrement = 1, wrap_around = true) ⇒ Object
148 149 150 |
# File 'lib/yarbf.rb', line 148 def decrease(decrement = 1, wrap_around = true) self.increase(-decrement, wrap_around) end |
#increase(increment = 1, wrap_around = true) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/yarbf.rb', line 140 def increase(increment = 1, wrap_around = true) if !wrap_around && (@value + increment < 0 || @value + increment > 255) fail 'Overflow or underflow happened while forbidden!' else @value = (@value + increment) % 256 end end |