diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 3c14454437..d3aea636a1 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -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 diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index 3c1d574e32..a28abe5211 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -113,6 +113,7 @@ class TC_OpenStruct < Test::Unit::TestCase os = OpenStruct.new(h) assert_equal '#: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