Tuesday 20 August 2013

Using Math Symbols Stored in an Array as a String

Using Math Symbols Stored in an Array as a String

I'm very new to Ruby and I'm trying to use math symbols that are stored in
an array as strings to perform math. This is for a Reverse Polish Notation
calculator I'm working on. For example:
var = ['1','2','+']
I've puzzled through enough regular expressions to figure out how to
differentiate numbers from non-numbers in an if statement, but I'm trying
to figure out how I could make the following work to produce -1.
var[0] var[2] var[1] #=> 1 - 2
Does anyone know how to change the string '-' back into the math symbol?

No comments:

Post a Comment