Class: Arithmetic::Tokenizer
- Inherits:
-
Object
- Object
- Arithmetic::Tokenizer
- Defined in:
- lib/arithmetic/parser.rb
Instance Method Summary collapse
Instance Method Details
#tokenize(exp) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/arithmetic/parser.rb', line 71 def tokenize(exp) tokens = exp .gsub('*', ' * ') .gsub('/', ' / ') .gsub('+', ' + ') .gsub('-', ' - ') .gsub('(', ' ( ') .gsub(')', ' ) ') .split(' ') tokens = parse_operators(tokens) replace_unary_minus(tokens) end |