Comment restriction

In ruby ​​1.9, the conditions on which the line ended were relaxed, so now we can start the line with a period showing the method call. This is convenient when we have mixed chain and non-attached methods and want to show where the next immediate starts. Without this new feature, it would be best to use indentation:

method1(args1). method2(args2). method3(args3) method4(args4). method5(args5). method6(args6) 

or insert an empty string. But this was inconvenient, because we must pay attention to the indentation and at the same time do not forget to set a period after each method call, except for the last in the chain. Because of this, I created so many errors, either with an odd or missing period. Thanks to the new function, we can do it much nicer than:

 method1(args1) .method2(args2) .method3(args3) method4(args4) .method5(args5) .method6(args6) 

where the period visually functions as indentation.

The problem is that when you want to insert comments before a line starting with a period, it returns an error.

 method1(args1) # method2 does blah blah .method2(args2) # method3 then does foo foo .method3(args3) method4(args4) # method5 does blah blah .method5(args5) # method6 then does bar bar .method6(args6) # => error 

or

 method1(args1) # method2 does blah blah .method2(args2) # method3 then does foo foo .method3(args3) method4(args4) # method5 does blah blah .method5(args5) # method6 then does bar bar .method6(args6) # => error 

It seems that "#...." does not just drop out, but somehow interacts with the code. What's happening? What is the exact limitation here? When the periods were at the end of the line, this did not happen.

 method1(args1). # method2 does blah blah method2(args2). # method3 then does foo foo method3(args3) method4(args4). # method5 does blah blah method5(args5). # method6 then does bar bar method6(args6) # => no error 
+6
source share
1 answer

The lexical parser is probably β€œfree” in that it will ignore one new line and the space immediately preceding the point. This probably does not allow multiple lines of newline. This splits the encoded statements into an incoherent mess, and it becomes much more difficult to handle without false positives. This is all said ...

If you need to add inline comments, this is probably an unacceptable place for concise, coded statements.

+1
source

Source: https://habr.com/ru/post/886049/


All Articles