ruby-on-rails – 通过多行链接调用的Ruby约定

这是什么约定?

我使用下面的风格,但不确定它是首选,因为如果我错过了一个点,在结束我可以遇到很多问题,没有意识到。

query = reservations_scope.for_company(current_company).joins{property.development}.
  group{property.development.id}.
  group{property.development.name}.
  group{property.number}.
  group{created_at}.
  group{price}.
  group{reservation_path}.
  group{company_id}.
  group{user_id}.
  group{fee_paid_date}.
  group{contract_exchanged_date}.
  group{deposit_paid_date}.
  group{cancelled_date}.
  select_with_reserving_agent_name_for(current_company, [
                                       "developments.id as dev_id",
                                       "developments.name as dev_name",
                                       "properties.number as prop_number",
                                       "reservations.created_at",
                                       "reservations.price",
                                       "reservations.fee_paid_date",
                                       "reservations.contract_exchanged_date",
                                       "reservations.deposit_paid_date",
                                       "reservations.cancelled_date"
  ]).reorder("developments.name")
query.to_a # ....

那么什么是链接方法在多行的约定,我应该选择哪一个?

注意:我从Ruby coding style guide找不到一个很好的例子。

实际上在Ruby style guide有一个部分:

Adopt a consistent multi-line method chaining style. There are two
popular styles in the Ruby community, both of which are considered
good – leading . (Option A) and trailing . (Option B).

  • (Option A) When continuing a chained method invocation on
    another line keep the . on the second line.

    06000

  • (Option B) When continuing a chained method invocation on another line,
    include the . on the first line to indicate that the
    expression continues.

    06001

A discussion on the merits of both alternative styles can be found
07001.

http://stackoverflow.com/questions/12906048/ruby-convention-for-chaining-calls-over-multiple-lines

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:ruby-on-rails – 通过多行链接调用的Ruby约定