Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I escape #{ from string interpolation

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"
like image 287
Nick Avatar asked Aug 21 '09 08:08

Nick


1 Answers

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
like image 150
austinfromboston Avatar answered Sep 20 '22 22:09

austinfromboston