문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top