summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-31 08:43:09 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-31 08:43:09 +0000
commitbabb80f4a9562db3b45792059bf8e21c22ed2058 (patch)
tree2de491b80e8336dd868871d89b9b0fcd39781ed4 /lib/set.rb
parente03d266c1dbf82c25fd63a2a4a1a9665dbc1bab4 (diff)
* lib/set.rb (Set#{each,reject!,select!}, SortedSet#each): Pass
the original block through instead of creating one that only yields the passed argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rwxr-xr-xlib/set.rb24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/set.rb b/lib/set.rb
index 9727ba3..19bb892 100755
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -228,9 +228,9 @@ class Set
# Calls the given block once for each element in the set, passing
# the element as parameter. Returns an enumerator if no block is
# given.
- def each
- block_given? or return enum_for(__method__)
- @hash.each_key { |o| yield(o) }
+ def each(&block)
+ block or return enum_for(__method__)
+ @hash.each_key(&block)
self
end
@@ -296,19 +296,19 @@ class Set
# Equivalent to Set#delete_if, but returns nil if no changes were
# made.
- def reject!
- block_given? or return enum_for(__method__)
+ def reject!(&block)
+ block or return enum_for(__method__)
n = size
- delete_if { |o| yield(o) }
+ delete_if(&block)
size == n ? nil : self
end
# Equivalent to Set#keep_if, but returns nil if no changes were
# made.
- def select!
- block_given? or return enum_for(__method__)
+ def select!(&block)
+ block or return enum_for(__method__)
n = size
- keep_if { |o| yield(o) }
+ keep_if(&block)
size == n ? nil : self
end
@@ -603,9 +603,9 @@ class SortedSet < Set
super
end
- def each
- block_given? or return enum_for(__method__)
- to_a.each { |o| yield(o) }
+ def each(&block)
+ block or return enum_for(__method__)
+ to_a.each(&block)
self
end