Ruby 2.7 allows placing of comment lines between fluent dots

With Ruby 2.7, comment lines can now be placed between fluent dots.

Before Ruby 2.7

Class
  # .methods or comment
  .inspect
=> syntax error, unexpected '.', expecting end-of-input

After Ruby 2.7

Class
  # .methods or comment
  .inspect
=> "Class"

This feature comes in handy especially when debugging some set of changes or when we need to explain the purpose behind a particular chained method separately.

For instance, following is allowed,

Post
  # Complex scope call which needs separate comment to explain
  .only_published_with_info(filter)
  # .with_single_author # Commented for debugging
  .with_generic_notes

Note that placing one or more blank lines between the chained methods is not allowed,

Post

  .only_published_with_info(filter)
=> syntax error, unexpected '.', expecting end-of-input

Need help on your Ruby on Rails or React project?

Join Our Newsletter