From b2d04067776787cb81095fb8c431f4165141ce11 Mon Sep 17 00:00:00 2001 From: Matias Flores Date: Sun, 27 Sep 2009 18:07:48 -0300 Subject: [PATCH] Prefer tap to returning in ActiveSupport --- .../lib/active_support/core_ext/array/grouping.rb | 2 +- .../lib/active_support/core_ext/enumerable.rb | 2 +- .../core_ext/range/blockless_step.rb | 2 +- .../lib/active_support/xml_mini/libxml.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index f782f8f..239e035 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -33,7 +33,7 @@ module ActiveSupport #:nodoc: if block_given? collection.each_slice(number) { |slice| yield(slice) } else - returning [] do |groups| + [].tap do |groups| collection.each_slice(number) { |group| groups << group } end end diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 2c5f59b..3d796c2 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -75,7 +75,7 @@ module Enumerable # (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1 # def each_with_object(memo, &block) - returning memo do |m| + memo.tap do |m| each do |element| block.call(element, m) end diff --git a/activesupport/lib/active_support/core_ext/range/blockless_step.rb b/activesupport/lib/active_support/core_ext/range/blockless_step.rb index 6fa1eb5..02d83fe 100644 --- a/activesupport/lib/active_support/core_ext/range/blockless_step.rb +++ b/activesupport/lib/active_support/core_ext/range/blockless_step.rb @@ -12,7 +12,7 @@ module ActiveSupport #:nodoc: if block_given? step_without_blockless(value, &block) else - returning [] do |array| + [].tap do |array| step_without_blockless(value) { |step| array << step } end end diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb index 3586b24..18630dd 100644 --- a/activesupport/lib/active_support/xml_mini/libxml.rb +++ b/activesupport/lib/active_support/xml_mini/libxml.rb @@ -101,7 +101,7 @@ module LibXML # Hash to merge the array into def children_array_to_hash(hash={}) hash[child.name] = map do |child| - returning({}) { |sub_hash| child.children_to_hash(sub_hash) } + {}.tap { |sub_hash| child.children_to_hash(sub_hash) } end hash end -- 1.6.0.4