ruby 没有换行符的Ruby多行字符串-AND-Ruby多行字符串,没有连接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 没有换行符的Ruby多行字符串-AND-Ruby多行字符串,没有连接相关的知识,希望对你有一定的参考价值。

##
# by SoAwesomeMan
str =<<-EOS.gsub(/^[\s\t]*|[\s\t]*\n/, '') # no space "\s" for new line "\n"; kill tabs too
   select awesome, awesome, awesome, awesome, awesome, awesome,   
   from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,   
   where cool cool cool cool cool cool cool cool cool cool cool'
EOS
# => "select awesome, awesome, awesome, awesome, awesome, awesome,from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,where cool cool cool cool cool cool cool cool cool cool cool'"

str =<<-EOS.gsub(/^[\s\t]*/, '').gsub(/[\s\t]*\n/, ' ').strip # yes space "\s" for new line "\n"; kill tabs too
   select awesome, awesome, awesome, awesome, awesome, awesome,   
   from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,   
   where cool cool cool cool cool cool cool cool cool cool cool'
EOS
# => "select awesome, awesome, awesome, awesome, awesome, awesome, from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, where cool cool cool cool cool cool cool cool cool cool cool'"

##
# via http://stackoverflow.com/questions/2337510/ruby-can-i-write-multi-line-string-with-no-concatenation
# by nocache => http://stackoverflow.com/users/778675/nocache
# "if you don't mind the extra newlines being inserted:"
 conn.exec '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'

# "Alternatively you can use a heredoc:"
<<-eos
   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'
eos

以上是关于ruby 没有换行符的Ruby多行字符串-AND-Ruby多行字符串,没有连接的主要内容,如果未能解决你的问题,请参考以下文章

Python 操作Redis

python爬虫入门----- 阿里巴巴供应商爬虫

Python词典设置默认值小技巧

《python学习手册(第4版)》pdf

Django settings.py 的media路径设置

Python中的赋值,浅拷贝和深拷贝的区别