I am doing some erb exercises and tests but i can’t seem to find how to split a stupid line that is too long in my editor. I’ve already tried using \n and \ but it doesn’t work as soon as I run it in terminal.
Here is the code:
erb_string = "
<h1><%= me[:name] + '\\'s ' + 'Blog'%></h1>
<ul>
<% animals.each do |animal| %>
<li><%= animal.upcase.reverse %></li>
<% end %>
</ul>
<p><%= 'My name is ' + me[:name] + ', my eyes are ' + me[:eyes] + '.' %></p>
<p><%= 'Let\\'s do some numbers! ' + numbers.last.to_s + '! is ' + numbers.inject(:*).to_s %></p> # I want to split this line in my editor because it is too long.
"
this should work.
if it didn’t work it was probably because you used two backslashes to escape the single quote and the first backlash escaped the second one so the single quote was not escaped.
Btw, when you have a string containing single quotes, you’d better encapsulate that in double quotes so you don’t have to escape the single quotes.