Skip to content

Commit 347e5da

Browse files
authored
Update STYLEGUIDE.md to clarify block usage
Removed examples and arguments against multiline chaining with `{...}` in the style guide. This is too much churn for little value. The monolith had >2000 offenses never corrected, and the alternative syntaxes just add more toil.
1 parent 67a7a67 commit 347e5da

1 file changed

Lines changed: 1 addition & 14 deletions

File tree

‎STYLEGUIDE.md‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,7 @@ arr.each { |elem| puts elem }
843843
* Prefer `{...}` over `do...end` for single-line blocks. Avoid using
844844
`{...}` for multi-line blocks (multiline chaining is always
845845
ugly). Always use `do...end` for "control flow" and "method
846-
definitions" (e.g. in Rakefiles and certain DSLs). Avoid `do...end`
847-
when chaining.
846+
definitions" (e.g. in Rakefiles and certain DSLs).
848847
<a name="squiggly-braces"></a><sup>[[link](#squiggly-braces)]</sup>
849848
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleblockdelimiters">RuboCop rule: Style/BlockDelimiters</a>
850849

@@ -858,20 +857,8 @@ names.each { |name| puts name }
858857
names.each do |name|
859858
puts name
860859
end
861-
862-
# good
863-
names.select { |name| name.start_with?("S") }.map { |name| name.upcase }
864-
865-
# bad
866-
names.select do |name|
867-
name.start_with?("S")
868-
end.map { |name| name.upcase }
869860
```
870861

871-
* Some will argue that multiline chaining would look OK with the use of `{...}`,
872-
but they should ask themselves: is this code really readable and can't the block's
873-
contents be extracted into nifty methods?
874-
875862
* Avoid `return` where not required.
876863
<a name="avoid-return"></a><sup>[[link](#avoid-return)]</sup>
877864
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#styleredundantreturn">RuboCop rule: Style/RedundantReturn</a>

0 commit comments

Comments
 (0)