在编程时,我经常做的一件事情是:
code = ''
code << "next line of code #{something}" << "\n"
code << "another line #{some_included_expression}" << "\n"
除了在每一行后面加上 << "\n"
或者 + "\n"
,是否有更好的方法? 这种方式似乎很低效。
我特别关注 Ruby 的解决方案。我在想类似这样的做法:
code = string.multiline do
"next line of code #{something}"
"another line #{some_included_expression}"
end
string。 - kinofrost