Class: BfRb::Memory
- Inherits:
-
Object
- Object
- BfRb::Memory
- Defined in:
- lib/bfrb/memory.rb
Overview
memory for brainfuck interpreter
Instance Method Summary collapse
-
#clear ⇒ Object
clear the memory.
-
#get(address) ⇒ Object
get the value at the given address.
-
#initialize ⇒ Memory
constructor
initialize the memory.
-
#set(address, value) ⇒ Object
set the given address to a certain value.
Constructor Details
#initialize ⇒ Memory
initialize the memory
6 7 8 |
# File 'lib/bfrb/memory.rb', line 6 def initialize clear end |
Instance Method Details
#clear ⇒ Object
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 |