1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
marcandre 2018-12-22 17:05:03 +00:00
parent 8ef2aae2d0
commit 1e30df6f77
4 changed files with 36 additions and 2 deletions

View file

@ -26,4 +26,11 @@ describe "OpenStruct#to_h" do
@to_h[:age] = 71
@os.age.should == 70
end
ruby_version_is "2.6" do
it "converts [key, value] pairs returned by the block to a hash" do
h = @os.to_h {|key, value| [key.to_s, value * 2]}
h.should == {"name" => "John SmithJohn Smith", "age" => 140, "pension" => 600}
end
end
end