mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/set.rb (Set#each, SortedSet#each, TC_Set#test_each): Return
an enumerator if no block is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
67acbe3954
commit
e7f65f6ba7
2 changed files with 12 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Apr 23 11:49:54 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* lib/set.rb (Set#each, SortedSet#each, TC_Set#test_each): Return
|
||||
an enumerator if no block is given.
|
||||
|
||||
Wed Apr 23 00:36:03 2008 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* test/openssl/test_ssl.rb (start_server): add timeout to server.join.
|
||||
|
|
12
lib/set.rb
12
lib/set.rb
|
@ -2,7 +2,7 @@
|
|||
#--
|
||||
# set.rb - defines the Set class
|
||||
#++
|
||||
# Copyright (c) 2002 Akinori MUSHA <knu@iDaemons.org>
|
||||
# Copyright (c) 2002-2008 Akinori MUSHA <knu@iDaemons.org>
|
||||
#
|
||||
# Documentation by Akinori MUSHA and Gavin Sinclair.
|
||||
#
|
||||
|
@ -204,8 +204,10 @@ class Set
|
|||
end
|
||||
|
||||
# Calls the given block once for each element in the set, passing
|
||||
# the element as parameter.
|
||||
# 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) }
|
||||
self
|
||||
end
|
||||
|
@ -511,6 +513,7 @@ class SortedSet < Set
|
|||
end
|
||||
|
||||
def each
|
||||
block_given? or return enum_for(__method__)
|
||||
to_a.each { |o| yield(o) }
|
||||
end
|
||||
|
||||
|
@ -925,9 +928,8 @@ class TC_Set < Test::Unit::TestCase
|
|||
ary = [1,3,5,7,10,20]
|
||||
set = Set.new(ary)
|
||||
|
||||
assert_raises(LocalJumpError) {
|
||||
set.each
|
||||
}
|
||||
e = set.each
|
||||
assert_instance_of(Enumerable::Enumerator, e)
|
||||
|
||||
assert_nothing_raised {
|
||||
set.each { |o|
|
||||
|
|
Loading…
Add table
Reference in a new issue