diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-20 15:06:56 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-20 15:06:56 +0000 |
commit | abe75149d14d3286d3051c9e961ab6473a243a19 (patch) | |
tree | f33ad9fcd4569f51d7f0b85fefb751597211438d /test/ruby/test_struct.rb | |
parent | e76eebd79be9fa3cb59d0ea6e4ce8214cc6e56ad (diff) | |
download | ruby-abe75149d14d3286d3051c9e961ab6473a243a19.tar.gz |
Enumerable#to_h with block and so on
[Feature #15143]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_struct.rb')
-rw-r--r-- | test/ruby/test_struct.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index edcd111acb..4748419d6b 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -362,6 +362,13 @@ module TestStruct assert_equal({a:1, b:2, c:3, d:4, e:5, f:6}, o.to_h) end + def test_to_h_block + klass = @Struct.new(:a, :b, :c, :d, :e, :f) + o = klass.new(1, 2, 3, 4, 5, 6) + assert_equal({"a" => 1, "b" => 4, "c" => 9, "d" => 16, "e" => 25, "f" => 36}, + o.to_h {|k, v| [k.to_s, v*v]}) + end + def test_question_mark_in_member klass = @Struct.new(:a, :b?) x = Object.new |