зеркало из https://github.com/github/ruby.git
* lib/set.rb (Set#collect, Set#select): Back out. I thought it
was consistent but turned out to be wrong. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ea40df71fc
Коммит
489bf84b9f
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Jun 3 15:00:22 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* lib/set.rb (Set#collect, Set#select): Back out. I thought it
|
||||||
|
was consistent but turned out to be wrong.
|
||||||
|
|
||||||
Tue Jun 3 13:41:08 2008 Akinori MUSHA <knu@iDaemons.org>
|
Tue Jun 3 13:41:08 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* lib/set.rb (Set#collect, Set#select): Override Enumerable
|
* lib/set.rb (Set#collect, Set#select): Override Enumerable
|
||||||
|
|
21
lib/set.rb
21
lib/set.rb
|
@ -255,32 +255,13 @@ class Set
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Calls the given block once for each element and returns a new set
|
# Replaces the elements with ones returned by collect().
|
||||||
# containing the values returned by the block.
|
|
||||||
def collect
|
|
||||||
block_given? or return enum_for(__method__)
|
|
||||||
set = self.class.new
|
|
||||||
each { |o| set << yield(o) }
|
|
||||||
end
|
|
||||||
alias map collect
|
|
||||||
|
|
||||||
# Replaces the values with ones returned by collect().
|
|
||||||
def collect!
|
def collect!
|
||||||
block_given? or return enum_for(__method__)
|
block_given? or return enum_for(__method__)
|
||||||
replace(collect)
|
replace(collect)
|
||||||
end
|
end
|
||||||
alias map! collect!
|
alias map! collect!
|
||||||
|
|
||||||
# Calls the given block once for each element and returns a new set
|
|
||||||
# containing those elements for which the block returns a true
|
|
||||||
# value.
|
|
||||||
def select
|
|
||||||
block_given? or return enum_for(__method__)
|
|
||||||
set = self.class.new
|
|
||||||
each { |o| set << o if yield(o) }
|
|
||||||
set
|
|
||||||
end
|
|
||||||
|
|
||||||
# Equivalent to Set#delete_if, but returns nil if no changes were
|
# Equivalent to Set#delete_if, but returns nil if no changes were
|
||||||
# made.
|
# made.
|
||||||
def reject!
|
def reject!
|
||||||
|
|
Загрузка…
Ссылка в новой задаче