forked from airbnb/ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
https://github.com/getfretless/ruby#indentation
Here's one I slightly disagree with:
I personally would like to see:
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'
endwith the when's and else indented 2-spaces over either of these (the AirBnB recommendations):
case
when song.name == 'Misty'
puts 'Not again!'
when song.duration > 120
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
else
song.play
end
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'
endI think I understand why AirBnB and others don't like this, though.
Case doesn't take a block, and if you indent your whens and else, the else doesn't line up with end.
kind = case year
when 1850..1889
'Blues'
when 1890..1909
'Ragtime'
else
'Jazz'
endBut I would even prefer that.
Or even this:
case something
when 1850..1889 then 'Blues'
when 1890..1909 then 'Ragtime'
else
'Jazz'
endI think of the indentation as being the "method body", as that's where the meat is, and it is more like an other control structures (like if), so it makes sense to me, and is more aesthetically pleasing to have it indented (IMO).
Metadata
Metadata
Assignees
Labels
No labels