Project

General

Profile

Bug #13169 ยป ostruct_each_pair.patch

stomar (Marcus Stollsteimer), 01/30/2017 08:51 PM

View differences:

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
    (1-1/1)