Class: BfRb::Memory

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

Overview

memory for brainfuck interpreter

Instance Method Summary collapse

Constructor Details

#initializeMemory

initialize the memory



6
7
8
# File 'lib/bfrb/memory.rb', line 6

def initialize
	clear
end

Instance Method Details

#clearObject

clear the memory



24
25
26
# File 'lib/bfrb/memory.rb', line 24

def clear
	@mem = {}
end

#get(address) ⇒ Object

get the value at the given address



11
12
13
14
15
16
# File 'lib/bfrb/memory.rb', line 11

def get(address)
	unless @mem.has_key?(address)
		set(address, 0)
	end
	return @mem[address]
end

#set(address, value) ⇒ Object

set the given address to a certain value



19
20
21
# File 'lib/bfrb/memory.rb', line 19

def set(address, value)
	@mem[address] = value
end