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

Multi line conditionals assignment indentation #179

Closed
fuadsaud opened this issue May 31, 2013 · 2 comments
Closed

Multi line conditionals assignment indentation #179

fuadsaud opened this issue May 31, 2013 · 2 comments

Comments

@fuadsaud
Copy link
Contributor

So, checking the guide, I didn't find mentions to conditional assignment indentation. Should it be like this:

result = if a.empty?
  # couple of statements
else
   # other statements
end

or this:

result = if a.empty?
               # couple of statements
             else
               # other statements
             end

I for instance prefer the first one, since it doesn't require realigning the whole thing when the variable name changes, it is closer to the block syntax and it doesn't create a weird whitespace hole on the left side. But this seems to go against the case example provided on the guide:

kind = case year
       when 1850..1889 then 'Blues'
       when 1890..1909 then 'Ragtime'
       when 1910..1929 then 'New Orleans Jazz'
       when 1930..1939 then 'Swing'
       when 1940..1950 then 'Bebop'
       else 'Jazz'
       end

I know case is an edge case (oh), but this may get people confused.

What do you think?

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 5, 2013

Actually I think it should be like this:

result = if a.empty?
             else
             end

Hmm, the else and end should be aligned with the if, but for some reason it's not displayed properly.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 16, 2013

Maybe this should be added as a rule if we can get the indentation correct :-)

Tsagadai pushed a commit to Tsagadai/ruby-style-guide that referenced this issue Oct 13, 2014
marocchino pushed a commit to marocchino/ruby-style-guide that referenced this issue Aug 11, 2015
shyouhei pushed a commit to shyouhei/ruby-style-guide that referenced this issue Nov 11, 2015
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

2 participants