Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a comment in the middle of a call chain

Tags:

comments

ruby

How can I add a comment in the middle of a call chain?

I see that Ruby throws parse error when I try to add a comment in the middle of a call chain like:

Tag.joins(:taggings)
   # Wanted to add comment here cause it's long 
   # and takes multiple lines
   .where(...)
   .where(...)
   .where(...)
   # And here
   .group(...)
   .order(...)
like image 225
Vedmant Avatar asked Sep 06 '25 11:09

Vedmant


1 Answers

Change to this structure:

Tag.joins(:taggings).
   # Comment 1
   # Comment 2
   where(...).
   where(...).
   where(...).
   # And here
   group(...).
   order(...)

Method . Dot at end will instruct the parser that expression hasn't ended and logical method chain will arrive.

like image 102
kiddorails Avatar answered Sep 09 '25 12:09

kiddorails