diff options
author | Shugo Maeda <shugo@ruby-lang.org> | 2021-09-11 18:49:12 +0900 |
---|---|---|
committer | Shugo Maeda <shugo@ruby-lang.org> | 2021-09-11 18:52:25 +0900 |
commit | c60dbcd1c55cd77a24c41d5e1a9555622be8b2b8 (patch) | |
tree | 318d03414f630b0d31cbaf48a740965af4dd4615 /test/ruby | |
parent | 64e056a4c5d4595cd2c36aabc747cca32f4b5395 (diff) | |
download | ruby-c60dbcd1c55cd77a24c41d5e1a9555622be8b2b8.tar.gz |
Allow value omission in Hash literals
`{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_hash.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index f79879c20a..5aee1b5d5c 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -2178,4 +2178,21 @@ class TestHash < Test::Unit::TestCase end; end end + + def test_value_omission + x = 1 + y = 2 + assert_equal({x: 1, y: 2}, {x:, y:}) + assert_equal({one: 1, two: 2}, {one:, two:}) + end + + private + + def one + 1 + end + + def two + 2 + end end |