Deterministic Finite Automata in Ruby