在写程序的时候,有时候一行字符会非常的长,比如
string1 = “string string string string string string string string string string string string string”
如果全部写在一行, 程序员都不喜欢看。
那怎么办了?
1.
str = 'this is a multi-line string'\
' using implicit concatenation'\
' to prevent spare \n\'s'
=> "this is a multi-line string using implicit concatenation to eliminate spare \\n's"
2.
p <<END_SQL.gsub(/\s+/, " ").strip SELECT * FROM users ORDER BY users.id DESC END_SQL # >> "SELECT * FROM users ORDER BY users.id DESC"
3.
%q{select attr1, attr2, attr3, attr4, attr5, attr6, attr7 from table1, table2, table3, etc, etc, etc, etc, etc, where etc etc etc etc etc etc etc etc etc etc etc etc etc}
4.
%Q{select attr1, attr2, attr3, attr4, attr5, attr6, attr7 from #{table_names}, where etc etc etc etc etc etc etc etc etc etc etc etc etc}