Skip to content
Merged
Changes from all commits
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
20 changes: 3 additions & 17 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,9 @@ end
arr.each { |elem| puts elem }
```

* Prefer `{...}` over `do...end` for single-line blocks. Avoid using
`{...}` for multi-line blocks (multiline chaining is always
ugly). Always use `do...end` for "control flow" and "method
definitions" (e.g. in Rakefiles and certain DSLs). Avoid `do...end`
when chaining.
* Prefer `{...}` over `do...end` for single-line blocks. Avoid using
`{...}` for multi-line blocks. Always use `do...end` for "control flow" and "method
definitions" (e.g. in Rakefiles and certain DSLs).
<a name="squiggly-braces"></a><sup>[[link](#squiggly-braces)]</sup>
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleblockdelimiters">RuboCop rule: Style/BlockDelimiters</a>

Expand All @@ -858,20 +856,8 @@ names.each { |name| puts name }
names.each do |name|
puts name
end

# good
names.select { |name| name.start_with?("S") }.map { |name| name.upcase }

# bad
names.select do |name|
name.start_with?("S")
end.map { |name| name.upcase }
```

* Some will argue that multiline chaining would look OK with the use of `{...}`,
but they should ask themselves: is this code really readable and can't the block's
contents be extracted into nifty methods?

* Avoid `return` where not required.
<a name="avoid-return"></a><sup>[[link](#avoid-return)]</sup>
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleredundantreturn">RuboCop rule: Style/RedundantReturn</a>
Expand Down
Loading