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
This commit is contained in:
nobu 2018-09-20 15:06:56 +00:00
parent e76eebd79b
commit abe75149d1
16 changed files with 243 additions and 30 deletions

View file

@ -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