mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 19:44:01 +02:00
Allow value omission in Hash literals
`{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
This commit is contained in:
parent
64e056a4c5
commit
c60dbcd1c5
2 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue