зеркало из https://github.com/github/ruby.git
* lib/ostruct.rb (Struct#each_pair): Return an enumerator with size
Patch by Kenichi Kamiya. [Fixes GH-383] * test/ostruct/test_ostruct.rb: Added tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
99d5d90f2f
Коммит
5b5de3984e
|
@ -125,7 +125,7 @@ class OpenStruct
|
|||
# data.each_pair.to_a # => [[:country, "Australia"], [:population, 20000000]]
|
||||
#
|
||||
def each_pair
|
||||
return to_enum __method__ unless block_given?
|
||||
return to_enum(__method__) { @table.size } unless block_given?
|
||||
@table.each_pair{|p| yield p}
|
||||
end
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ class TC_OpenStruct < Test::Unit::TestCase
|
|||
os = OpenStruct.new(h)
|
||||
assert_equal '#<Enumerator: #<OpenStruct name="John Smith", age=70, pension=300>:each_pair>', os.each_pair.inspect
|
||||
assert_equal [[:name, "John Smith"], [:age, 70], [:pension, 300]], os.each_pair.to_a
|
||||
assert_equal 3, os.each_pair.size
|
||||
end
|
||||
|
||||
def test_eql_and_hash
|
||||
|
|
Загрузка…
Ссылка в новой задаче