Trying to convert a simple math string "1 2 3 * + 4 5 - /"
to an array of integers and/or symbols like [1, 2, 3, :*, :+, 4, 5, :-, :/]
.
Is there a more elegant (and extendable) solution than this?
def tokenize s
arr = s.split(/ /)
symbols = %w{ + - / * }
arr.collect! do |c|
if symbols.include?(c)
c.to_sym
else
c.to_i
end
end
end