mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
e03d266c1d
commit
babb80f4a9
2 changed files with 18 additions and 12 deletions
|
@ -1,3 +1,9 @@
|
|||
Fri Aug 31 17:38:43 2012 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* lib/set.rb (Set#{each,reject!,select!}, SortedSet#each): Pass
|
||||
the original block through instead of creating one that only
|
||||
yields the passed argument.
|
||||
|
||||
Fri Aug 31 16:23:20 2012 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* lib/ipaddr.rb: Introduce several new error classes where only
|
||||
|
|
24
lib/set.rb
24
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue