I want to execute math expression which is in string like this sample strings:
A = "23>=34"B = "77<90"C = "33>77"
and I want some function like if exec_string(A) which should return true or false.
Currently I am using this method:
rest = --- # I am splitting the string in to three(L- as left number cmpr- as compare and R- as right number )
class_name.calc(rest[0],rest[1],rest[2])
def self.calc(L,cmpr,R)
case cmpr
when "<"
if L.to_i < R.to_i
return true
end
....
....
....
end
end
Which could not handle lot of cases. Any help?
evalandbindings. Perhaps someone with more experience with these functions could comment on whether they're bad practice and why.