aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG13
-rw-r--r--activesupport/lib/active_support/core_ext/enumerable.rb8
-rw-r--r--activesupport/test/core_ext/enumerable_test.rb10
3 files changed, 13 insertions, 18 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 670584b8eb..59fc6c27ed 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,18 @@
*SVN*
+* Remove Enumerable#first_match since break(value) handles the use case well enough. [Nicholas Seckar]
+ Enumerable#first_match was like detect, but instead of returning the matching element, the yielded value returned. For example:
+
+ user_xml = adapters(:from => User, :to => Xml).first_match do |adapter|
+ adapter.adapt @user
+ end
+
+ But this is just as easily done with:
+
+ user_xml = adapters(:from => User, :to => Xml).each do
+ break adapter.adapt(@user)
+ end
+
* Make Array#in_groups_of just return the grouped collection if a block isn't given. [Marcel Molina Jr.]
* Don't destroy a HashWithIndifferentAccess if symbolize_keys! or stringify_keys! is called on it. Closes #5076. [Marcel Molina Jr., guy.naor@famundo.com]
diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb
index a49c4c701b..5c556ff98d 100644
--- a/activesupport/lib/active_support/core_ext/enumerable.rb
+++ b/activesupport/lib/active_support/core_ext/enumerable.rb
@@ -1,12 +1,4 @@
module Enumerable #:nodoc:
- def first_match
- match = nil
- each do |items|
- break if match = yield(items)
- end
- match
- end
-
# Collect an enumerable into sets, grouped by the result of a block. Useful,
# for example, for grouping records by date.
#
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb
index 6ca41f9116..df14200e42 100644
--- a/activesupport/test/core_ext/enumerable_test.rb
+++ b/activesupport/test/core_ext/enumerable_test.rb
@@ -3,16 +3,6 @@ require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/enumerable'
class EnumerableTests < Test::Unit::TestCase
- def test_first_match_no_match
- [[1, 2, 3, 4, 5], (1..9)].each {|a| a.first_match {|x| x > 10}}
- end
-
- def test_first_match_with_match
- assert_equal true, [1, 2, 3, 4, 5, 6].first_match {|x| x > 4}
- assert_equal true, (1..10).first_match {|x| x > 9}
- assert_equal :aba, {:a => 10, :aba => 50, :bac => 40}.first_match {|k, v| k if v > 45}
- end
-
def test_group_by
names = %w(marcel sam david jeremy)
klass = Class.new