views:

105

answers:

2

How do I make the following string cast:

"ln(5*x)" -> "Math.log(5*x)"
A: 
"math.log(#{"ln(5*x)"[/ln\((.*)\)/,1]})"
khelll
Ok, now, is there any gem or library to generalize the solution, transforming all the math-like strings into their Ruby expression representation (with all the Math affixes)?
gmile
You'd better search on github.com
khelll
They're just strings: treat them like strings. It's of no consequence that they look like math functions.
glenn jackman
+2  A: 

"ln(5*x)".sub('ln','Math.log') #=> "Math.log(5*x)"

glenn jackman
Not bad at all O_o
gmile