diff options
author | miloops <miloops@gmail.com> | 2008-07-29 23:14:56 -0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-30 01:52:16 -0700 |
commit | 2617d0dc5ced4b354bff9633bddafdf80ad5a711 (patch) | |
tree | 55d3b7e076ab8541c4a890aeb6226ded657d35bc /activesupport/lib/active_support | |
parent | c4038764d2b4c05178cceb22066e0ece59fe49d2 (diff) | |
download | rails-2617d0dc5ced4b354bff9633bddafdf80ad5a711.tar.gz rails-2617d0dc5ced4b354bff9633bddafdf80ad5a711.tar.bz2 rails-2617d0dc5ced4b354bff9633bddafdf80ad5a711.zip |
Performance: grouping helpers should use yield instead of block as argument. [#723 state:resolved]
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/grouping.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index df37afb053..dd1484f8fa 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -19,7 +19,7 @@ module ActiveSupport #:nodoc: # %w(1 2 3).in_groups_of(2, false) {|g| p g} # ["1", "2"] # ["3"] - def in_groups_of(number, fill_with = nil, &block) + def in_groups_of(number, fill_with = nil) if fill_with == false collection = self else @@ -31,7 +31,7 @@ module ActiveSupport #:nodoc: end if block_given? - collection.each_slice(number, &block) + collection.each_slice(number) { |slice| yield(slice) } else returning [] do |groups| collection.each_slice(number) { |group| groups << group } @@ -87,11 +87,11 @@ module ActiveSupport #:nodoc: # # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]] # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]] - def split(value = nil, &block) - block ||= Proc.new { |e| e == value } + def split(value = nil) + using_block = block_given? inject([[]]) do |results, element| - if block.call(element) + if (using_block && yield(element)) || (value == element) results << [] else results.last << element |