Sho*_*eNN 5 ruby string comments
我有一个通过百分比字符串的多行字符串数组,如下所示:
array = %w(test
foo
bar)
Run Code Online (Sandbox Code Playgroud)
我想在foo条目中添加评论消息,例如
array = %w(test
# TODO: Remove this line after fix #1
foo
bar)
Run Code Online (Sandbox Code Playgroud)
有什么方法可以将其转换为基本数组吗?
array = ['test',
# TODO: Remove this line after fix #1
'foo',
'bar']
Run Code Online (Sandbox Code Playgroud)
唯一且棘手的方法:
array = %W(test
#@foo
bar).reject(&:empty?)
Run Code Online (Sandbox Code Playgroud)
注意大写W和reject
| 归档时间: |
|
| 查看次数: |
508 次 |
| 最近记录: |