I want to remove string interpolation for eval.
I have a lot of places with such code, so only one option is modifying the condition to unescape code.
I found a regexp that works well
"\#{user.name}"[/[^\#{}]+/]
as result, I have "user.name"
but such code removing curly braces in blocks as well
"\#{[1,2,3].map { |el| el }.join(',')}"[/[^\#{}]+/]
returns
"[1,2,3].map "
the expected result is:
"[1,2,3].map { |el| el }.join(',')"
Any ideas how to solve it?
your_str[/#({(?:[^{}]++|\g<1>)*})/, 1].gsub(/[{}]/, ""), see demo.evalsafe, don't bother. You would basically need to implement a Ruby static analyzer to truly do that.