Question

I saw this whilst browsing the code for the acts as commentable with threading gem

new \
  :commentable => obj,
  :body        => comment,
  :user_id     => user_id

From testing it out in the console, it looks like the backslash allows you append attributes on a new line, so that they're all aligned. Is there any more to it than that?

What's this idiom/technique called? Searching for rails backslash doesn't return anything useful.

Was it helpful?

Solution

It is exactly what you think it is. \ at the end of a line lets you continue your expression on the next line.

I am not sure if this has an official name ("multiline statement" maybe?).

PS: While looking for a name I was browsing the rubinius parser code. The \ skip code is implemented here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top