diff options
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/extract.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/extract.rb b/activesupport/lib/active_support/core_ext/array/extract.rb index 7641cb5064..cc5a8a3f88 100644 --- a/activesupport/lib/active_support/core_ext/array/extract.rb +++ b/activesupport/lib/active_support/core_ext/array/extract.rb @@ -7,15 +7,15 @@ class Array # numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # odd_numbers = numbers.extract! { |number| number.odd? } # => [1, 3, 5, 7, 9] # numbers # => [0, 2, 4, 6, 8] - def extract!(&block) - unless block_given? - to_enum(:extract!) { size } - else - extracted_elements, other_elements = partition(&block) + def extract! + return to_enum(:extract!) { size } unless block_given? - replace(other_elements) + extracted_elements = [] - extracted_elements + reject! do |element| + extracted_elements << element if yield(element) end + + extracted_elements end end |