在通话链中间添加评论

Ved*_*ant 2 ruby comments

如何在通话链中间添加评论?

当我尝试在调用链的中间添加注释时,我看到Ruby抛出解析错误:

Tag.joins(:taggings)
   # Wanted to add comment here cause it's long 
   # and takes multiple lines
   .where(...)
   .where(...)
   .where(...)
   # And here
   .group(...)
   .order(...)
Run Code Online (Sandbox Code Playgroud)

kid*_*ils 5

更改为以下结构:

Tag.joins(:taggings).
   # Comment 1
   # Comment 2
   where(...).
   where(...).
   where(...).
   # And here
   group(...).
   order(...)
Run Code Online (Sandbox Code Playgroud)

最后的方法.点将指示解析器表达式尚未结束,并且逻辑方法链将到达。

  • 不仅仅是解析器,对于那些可能不希望语句在(多行)注释后继续的程序员来说,它也是一个提示。 (3认同)