Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
add style for proc calling with simple blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Jones committed Apr 28, 2015
1 parent bdde52a commit 4364f00
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -1106,6 +1106,18 @@ condition](#safe-assignment-in-condition).
'test'.upcase
```

* <a name="single-action-blocks"></a>
Use the proc invocation shorthand when the invoked method is the only operation of a block.
<sup>[[link](#single-action-blocks)]</sup>

```Ruby
# bad
names.map { |name| name.upcase }

# good
names.map(&:upcase)
```

* <a name="single-line-blocks"></a>
Prefer `{...}` over `do...end` for single-line blocks. Avoid using `{...}`
for multi-line blocks (multiline chaining is always ugly). Always use
Expand All @@ -1130,7 +1142,7 @@ condition](#safe-assignment-in-condition).
end.map { |name| name.upcase }

# good
names.select { |name| name.start_with?('S') }.map { |name| name.upcase }
names.select { |name| name.start_with?('S') }.map(&:upcase)
```

Some will argue that multiline chaining would look OK with the use of {...},
Expand Down

0 comments on commit 4364f00

Please sign in to comment.