I want to have a text template file that would contain variables.
- the file is read
- variables replaced with its values
- the file is saved
- I tried to have a file with
#{my_variable}but actually the character#is escaped so#{my_variable}is not replaced with the value of the variable because it’s text. - tried to escape # in the text file
\#but it didn’t work
Is there any way that I don’t have to do search and replace in this scenario?
As clyfe mentioned, you should definitely be using ERB’s for this:
http://www.rrn.dk/rubys-erb-templating-system/
This will let you use variables, loops, methods, etc. and is far more robust.