class Brainclusterfuck::Memory
Attributes
size[R]
Public Class Methods
new(size)
click to toggle source
# File lib/brainclusterfuck/memory.rb, line 7 def initialize(size) @size = size.to_i @pointer = 0 @cells = Hash.new { 0 } end
Public Instance Methods
current_char()
click to toggle source
# File lib/brainclusterfuck/memory.rb, line 14 def current_char current_value.chr end
current_value()
click to toggle source
# File lib/brainclusterfuck/memory.rb, line 18 def current_value @cells[@pointer] end
modify_pointer(amount)
click to toggle source
# File lib/brainclusterfuck/memory.rb, line 27 def modify_pointer(amount) @pointer += amount raise MemoryError if (@pointer < 0 || @pointer >= @size) end
modify_value(amount)
click to toggle source
# File lib/brainclusterfuck/memory.rb, line 22 def modify_value(amount) # keep value in one byte @cells[@pointer] = (@cells[@pointer] + amount.to_i) & 0xFF end