diff options
-rw-r--r-- | lib/pp.rb | 11 | ||||
-rw-r--r-- | test/test_pp.rb | 5 |
2 files changed, 15 insertions, 1 deletions
@@ -223,7 +223,16 @@ class PP < PrettyPrint else sep.call end - yield(*v) + case v.last + when Hash + if Hash.ruby2_keywords_hash?(v.last) + yield(*v, **{}) + else + yield(*v) + end + else + yield(*v) + end } end diff --git a/test/test_pp.rb b/test/test_pp.rb index 3262417fba..cd16af6394 100644 --- a/test/test_pp.rb +++ b/test/test_pp.rb @@ -176,6 +176,11 @@ class PPSingleLineTest < Test::Unit::TestCase assert_equal("{1=>1}", PP.singleline_pp({ 1 => 1}, ''.dup)) # [ruby-core:02699] assert_equal("[1#{', 1'*99}]", PP.singleline_pp([1]*100, ''.dup)) end + + def test_hash_in_array + assert_equal("[{}]", PP.singleline_pp([->(*a){a.last}.ruby2_keywords.call(**{})], ''.dup)) + assert_equal("[{}]", PP.singleline_pp([Hash.ruby2_keywords_hash({})], ''.dup)) + end end class PPDelegateTest < Test::Unit::TestCase |