I have a heredoc where I am using #{}
to interpolate some other strings, but there is an instance where I also want to write the actual text #{some_ruby_stuff}
in my heredoc, WITHOUT it being interpolated. Is there a way to escape the #{.
I've tried "\", but no luck. Although it escapes the #{}
, it also includes the "\":
>> <<-END
#{RAILS_ENV} \#{RAILS_ENV}
END
=> " development \#{RAILS_ENV}\n"
For heredoc without having to hand-escape all your potential interpolations, you can use single-quote-style-heredoc. It works like this:
item = <<-'END'
#{code} stuff
whatever i want to say #{here}
END