class Rbfunge::Memory_Stack
memory stack for Befunge programs
Public Class Methods
new()
click to toggle source
initialize the memory
# File lib/rbfunge/memory_stack.rb, line 6 def initialize @stack = [] end
Public Instance Methods
dup()
click to toggle source
duplicate the top item
# File lib/rbfunge/memory_stack.rb, line 29 def dup top = pop push top push top end
pop()
click to toggle source
pop the first top element off the stack
# File lib/rbfunge/memory_stack.rb, line 11 def pop return @stack.empty? ? 0 : @stack.pop end
push(value)
click to toggle source
push an element onto the stack
# File lib/rbfunge/memory_stack.rb, line 16 def push(value) @stack.push value end
swap()
click to toggle source
swap the top two items in the stack
# File lib/rbfunge/memory_stack.rb, line 21 def swap first = pop second = pop push first push second end