From 1e30df6f77c79b07d1c65e450b0167861c180473 Mon Sep 17 00:00:00 2001 From: marcandre Date: Sat, 22 Dec 2018 17:05:03 +0000 Subject: ostruct.rb: Accept block for to_h [#15451]. Patch by Shuji Kobayashi. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ostruct/test_ostruct.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/ostruct') diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index d89bc94cc3..61a4822810 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -141,6 +141,13 @@ class TC_OpenStruct < Test::Unit::TestCase assert_equal(h, OpenStruct.new("name" => "John Smith", "age" => 70, pension: 300).to_h) end + def test_to_h_with_block + os = OpenStruct.new("country" => "Australia", :capital => "Canberra") + assert_equal({"country" => "AUSTRALIA", "capital" => "CANBERRA" }, + os.to_h {|name, value| [name.to_s, value.upcase]}) + assert_equal("Australia", os.country) + end + def test_each_pair h = {name: "John Smith", age: 70, pension: 300} os = OpenStruct.new(h) -- cgit v1.2.3