Bug #13169 ยป ostruct_each_pair.patch
| lib/ostruct.rb | ||
|---|---|---|
| def each_pair | ||
| return to_enum(__method__) { @table.size } unless block_given? | ||
| @table.each_pair{|p| yield p} | ||
| self | ||
| end | ||
| # | ||
| test/ostruct/test_ostruct.rb | ||
|---|---|---|
| def test_each_pair | ||
| h = {name: "John Smith", age: 70, pension: 300} | ||
| os = OpenStruct.new(h) | ||
| assert_equal os.object_id, os.each_pair { }.object_id | ||
| 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 | ||