summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--lib/set.rb29
-rw-r--r--version.h2
3 files changed, 37 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index b99767f7e31..5823c555bf3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Sun Jun 29 16:56:57 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * lib/set.rb (Set#delete_if): Call to_a.
+ (SortedSet#delete_if, TC_SortedSet#test_sortedset): Use super to
+ yield elements in sorted order; [ruby-core:17144] by Arthur
+ Schreiber.
+ (SortedSet#each, SortedSet#each, TC_Set#test_each)
+ (TC_SortedSet#test_sortedset): Return self; [ruby-dev:35002] by
+ Arthur Schreiber.
+
Sun Jun 29 16:49:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (search_method, remove_method, error_print, rb_alias)
diff --git a/lib/set.rb b/lib/set.rb
index 5a9287ba892..d3f85f8422c 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -228,7 +228,7 @@ class Set
# Deletes every element of the set for which block evaluates to
# true, and returns self.
def delete_if
- @hash.delete_if { |o,| yield(o) }
+ to_a.each { |o| @hash.delete(o) if yield(o) }
self
end
@@ -486,7 +486,7 @@ class SortedSet < Set
def delete_if
n = @hash.size
- @hash.delete_if { |o,| yield(o) }
+ super
@keys = nil if @hash.size != n
self
end
@@ -498,6 +498,7 @@ class SortedSet < Set
def each
to_a.each { |o| yield(o) }
+ self
end
def to_a
@@ -1161,11 +1162,33 @@ class TC_SortedSet < Test::Unit::TestCase
assert_equal([-10,-8,-6,-4,-2], s.to_a)
prev = nil
- s.each { |o| assert(prev < o) if prev; prev = o }
+ ret = s.each { |o| assert(prev < o) if prev; prev = o }
assert_not_nil(prev)
+ assert_same(s, ret)
s = SortedSet.new([2,1,3]) { |o| o * -2 }
assert_equal([-6,-4,-2], s.to_a)
+
+ s = SortedSet.new(['one', 'two', 'three', 'four'])
+ a = []
+ ret = s.delete_if { |o| a << o; o[0] == ?t }
+ assert_same(s, ret)
+ assert_equal(['four', 'one'], s.to_a)
+ assert_equal(['four', 'one', 'three', 'two'], a)
+
+ s = SortedSet.new(['one', 'two', 'three', 'four'])
+ a = []
+ ret = s.reject! { |o| a << o; o[0] == ?t }
+ assert_same(s, ret)
+ assert_equal(['four', 'one'], s.to_a)
+ assert_equal(['four', 'one', 'three', 'two'], a)
+
+ s = SortedSet.new(['one', 'two', 'three', 'four'])
+ a = []
+ ret = s.reject! { |o| a << o; false }
+ assert_same(nil, ret)
+ assert_equal(['four', 'one', 'three', 'two'], s.to_a)
+ assert_equal(['four', 'one', 'three', 'two'], a)
end
end
diff --git a/version.h b/version.h
index 6f62926eb64..40b6c13db1f 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-29"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20080629
-#define RUBY_PATCHLEVEL 239
+#define RUBY_PATCHLEVEL 240
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8