Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,12 @@ Translations of the guide are available in the following languages:
puts 'Not again!'
when song.duration > 120
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
when :minus_op, :minus_minus_op
stack.pop - stack.pop
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
stack.pop + stack.pop
when :int_literal, :some_complicate_explicit_name, :contains_musicians_with_arms, :str_interpolated
token.value
else
song.play
end
Expand All @@ -341,11 +345,26 @@ Translations of the guide are available in the following languages:
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
when :minus_op, :minus_minus_op
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this example, I think we're talking more about Good and Better than about Bad and Good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's just one other precedent in the style guide. I'm happy to make a simple Better block, and try to overall keep the examples 'deduped' to limit newlines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated @bbatsov. A smaller diff now, too.

stack.pop - stack.pop
when MyModule::SomeDomain::BETA_USERS,
MyModule::SomeDomain::INTERNAL_RELEASE
stack.pop + stack.pop
when :int_literal,
:some_complicate_explicit_name,
:contains_musicians_with_arms,
:str_interpolated
token.value
else
song.play
end
```

Put multiple when conditions on separate lines,
particularly where the conditions form long, complicated lines.
The 'bad' example also has the issue of causing the entire when line to
diff when only one of the conditions is changed or updated.

* <a name="indent-conditional-assignment"></a>
When assigning the result of a conditional expression to a variable,
preserve the usual alignment of its branches.
Expand Down