Class: BfInterpreter::BfCell

Inherits:
Object
  • Object
show all
Defined in:
lib/yarbf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#positionObject

Returns the value of attribute position.



133
134
135
# File 'lib/yarbf.rb', line 133

def position
  @position
end

#valueObject

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