Brainf**k interpreter in Ruby
Sure it can!

Steps I see to make it clean:


Create a class, define state attrs:

private

attr_reader :output, :code_pointer, :data_pointer, :input_pointer

define initialize method

def initialize(args = {})
  @code = args[:code]
  @input = args[:input]
  @output = ''
  @code_pointer, @data_pointer, @input_pointer = 0, 0, 0
end

define whens as a methods and give it right names: next_cell, prev_cell, increment, decrement, write_byte, read_byte and so on
define constant for configuration:

OPERATORS = {
  '&gt;' =&gt; :next_cell,
  '&lt;' =&gt; :prev_cell,
  '+' =&gt; :increment,
  ...
}

define method to evaluate code:

def evaluate_code
  code.each { |operator| public_send OPERATORS[operator] }
end

Finally instantiate object of your class and call evaluate_code

BrainLuck.new(code: code, input: input).evaluate_code



I think you'll love your object oriented result.