ruby-changes:31325
From: marcandre <ko1@a...>
Date: Thu, 24 Oct 2013 00:14:14 +0900 (JST)
Subject: [ruby-changes:31325] marcandRe: r43404 (trunk): * lib/ostruct.rb (Struct#each_pair): Return an enumerator with size
marcandre 2013-10-24 00:13:57 +0900 (Thu, 24 Oct 2013) New Revision: 43404 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43404 Log: * 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. Modified files: trunk/lib/ostruct.rb trunk/test/ostruct/test_ostruct.rb Index: lib/ostruct.rb =================================================================== --- lib/ostruct.rb (revision 43403) +++ lib/ostruct.rb (revision 43404) @@ -125,7 +125,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L125 # 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 Index: test/ostruct/test_ostruct.rb =================================================================== --- test/ostruct/test_ostruct.rb (revision 43403) +++ test/ostruct/test_ostruct.rb (revision 43404) @@ -113,6 +113,7 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L113 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/