# Stopping ruby from escaping characters

**URL:** <https://www.ruby-forum.com/t/stopping-ruby-from-escaping-characters/194040>\
**Category:** Ruby\
**Created:** [August 28, 2010, 9:42pm UTC](https://www.ruby-forum.com/t/stopping-ruby-from-escaping-characters/194040 "2010-08-28T21:42:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shef](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@Shef](https://www.ruby-forum.com/u/Shef)\
**Post date:** [August 28, 2010, 9:42pm UTC](https://www.ruby-forum.com/t/stopping-ruby-from-escaping-characters/194040/1 "2010-08-28T21:42:21Z")

</div>

I’m trying to open a file with variables encased inside the  
interpolation operator, but when I open the file it escapes the #  
character. I try and gsub it but it reinserts the escape character  
anyway. Is there anyway to make ruby ignore the # character so I can  
use variables in files?

---

<div class="post-metadata">

**Author:** ![Shef](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a587f6/32.png) [@Shef](https://www.ruby-forum.com/u/Shef)\
**Post date:** [August 28, 2010, 10:07pm UTC](https://www.ruby-forum.com/t/stopping-ruby-from-escaping-characters/194040/2 "2010-08-28T22:07:31Z")

</div>

On Sat, Aug 28, 2010 at 2:40 PM, Shef [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to open a file with variables encased inside the  
> interpolation operator, but when I open the file it escapes the #  
> character. I try and gsub it but it reinserts the escape character  
> anyway. Is there anyway to make ruby ignore the # character so I can  
> use variables in files?

When you read it in, it is a String, not code being interpreted.

Rather than trying to interpolate data in a file, try using ERB.

Here is the example from the docs written using a file rather than  
string:

> <https://gist.github.com/JoshCheek/555505>

Here is a quick hopefully straightforward primer:  
[http://github.com/JoshCheek/JoshsRubyKickstart/blob/master/cheatsheets/erb-embedded\_ruby.rb](http://github.com/JoshCheek/JoshsRubyKickstart/blob/master/cheatsheets/erb-embedded_ruby.rb)
