From 4364f0079464fc02ab2472a0d53e5b4cb9379e2f Mon Sep 17 00:00:00 2001 From: Zachary Jones Date: Tue, 24 Mar 2015 19:10:44 -0400 Subject: [PATCH] add style for proc calling with simple blocks --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e8da7f34..df7615883 100644 --- a/README.md +++ b/README.md @@ -1106,6 +1106,18 @@ condition](#safe-assignment-in-condition). 'test'.upcase ``` +* + Use the proc invocation shorthand when the invoked method is the only operation of a block. +[[link](#single-action-blocks)] + + ```Ruby + # bad + names.map { |name| name.upcase } + + # good + names.map(&:upcase) + ``` + * Prefer `{...}` over `do...end` for single-line blocks. Avoid using `{...}` for multi-line blocks (multiline chaining is always ugly). Always use @@ -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 {...},