NFA and DFA implementation using Ruby