Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird do block formatting in chained method calls #102

Open
martinos opened this issue May 7, 2018 · 6 comments
Open

Weird do block formatting in chained method calls #102

martinos opened this issue May 7, 2018 · 6 comments

Comments

@martinos
Copy link

martinos commented May 7, 2018

I notice that when I chain method calls and I add a do block at the end, the formatting gets weird.

res = [1, 2, 3].
  select { |a| a.odd? }.
  inject({}) do |memo, a|
  memo = memo + 1
  memo
end

I think that the following would be easier to understand:

res = [1, 2, 3].
  select { |a| a.odd? }.
  inject({}) do |memo, a|
     memo = memo + 1
     memo
  end
@martinos martinos changed the title Weird do block formatting on multiline method call chaining Weird do block formatting on multiline method call chain May 7, 2018
@martinos martinos changed the title Weird do block formatting on multiline method call chain Weird do block formatting in chained method calls May 7, 2018
@jona
Copy link

jona commented Dec 31, 2019

This would be amazing 👍

@rocketbop
Copy link

This seems to be the case when the do operator is on the left also.

Would a PR be accepted?

@gingermusketeer
Copy link
Member

@paublyrne I am not sure what you mean by the do operator being on the left. Do you have an example?

A PR for this issue sounds great!!

@rocketbop
Copy link

@gingermusketeer Sorry I meant dot operator, as in:

res = [1, 2, 3]
  .select { |a| a.odd? }
  .inject({}) do |memo, a|
  memo = memo + 1
  memo
end

Great I'll take a pass at it!

@gingermusketeer
Copy link
Member

@paublyrne Ah okay, covering that one as well would be great! Look forward to the PR :)

@theworkerant
Copy link

Great idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants