diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-03 18:25:28 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-02-03 18:25:28 +0000 |
commit | 4d7b999c77f7869df3a07abc263838eee3e8dd60 (patch) | |
tree | 492fdb2e83d6db0d64a12c791b2aa2ca22dc2a59 | |
parent | 0fe47fad55e15e890b7b45ffeaba47828760100d (diff) |
lib/ostruct.rb: Fix returned value of each_pair.
From a patch by Marcus Stollsteimer. [Fixes #13169]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/ostruct.rb | 1 | ||||
-rw-r--r-- | test/ostruct/test_ostruct.rb | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index bbf1743247..417ecf62b3 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -130,6 +130,7 @@ class OpenStruct def each_pair return to_enum(__method__) { @table.size } unless block_given? @table.each_pair{|p| yield p} + self end # diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index aeccc9209a..7df5200ca1 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -141,6 +141,7 @@ class TC_OpenStruct < Test::Unit::TestCase def test_each_pair h = {name: "John Smith", age: 70, pension: 300} os = OpenStruct.new(h) + assert_same os, os.each_pair{ } 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 |