При написании Ruby (клиентских скриптов) я вижу три способа создания более длинных строк, включая окончания строк, и все они «пахнут» для меня отталкивающе.
Есть ли более чистые и приятные способы?
Приращение переменной.
if render_quote?
quote = "Now that there is the Tec-9, a crappy spray gun from South Miami."
quote += "This gun is advertised as the most popular gun in American crime. Do you believe that shit?"
quote += "It actually says that in the little book that comes with it: the most popular gun in American crime."
quote += "Like they're actually proud of that shit."
puts quote
end
Heredocs (и незакрытые кавычки).
if render_quote?
quote =<<EOS
Now that there is the Tec-9, a crappy spray gun from South Miami.
This gun is advertised as the most popular gun in American crime. Do you believe that shit?
It actually says that in the little book that comes with it: the most popular gun in American crime.
Like they're actually proud of that shit.
EOS
puts quote
end
Или, просто не добавляя закрывающий тег:
if render_quote?
quote = "Now that there is the Tec-9, a crappy spray gun from South Miami.
This gun is advertised as the most popular gun in American crime. Do you believe that shit?
It actually says that in the little book that comes with it: the most popular gun in American crime.
Like they're actually proud of that shit."
puts quote
end
Или, при желании, с помощью gsub для исправления идентификации-вопросы (юк!?).
Объединение.
if render_quote?
quote = "Now that there is the Tec-9, a crappy spray gun from South Miami."
quote += "This gun is advertised as the most popular gun in American crime. Do you believe that shit?"
quote += "It actually says that in the little book that comes with it: the most popular gun in American crime."
quote += "Like they're actually proud of that shit."
puts quote
end
(цитата из Сэмюэля Л. Ипсума)
Я знаю, что наличие таких строк (т.е. логики представления) в моих сценариях само по себе является запахом, но я не знаю шаблона (кроме po-файлов или около того), чтобы очистить это.