Skip to content

Commit

Permalink
Ruby 3.1: Omit values in hashs and kwargs
Browse files Browse the repository at this point in the history
Values in Hash literals and keyword arguments can be omitted.

- See: [Feature #14579](https://bugs.ruby-lang.org/issues/14579)
- From: ruby#923
  • Loading branch information
EduardoGHdez committed Oct 8, 2022
1 parent 22bb5b2 commit fb95741
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/hash/hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@
h.hash.should == {x: [h]}.hash
# Like above, because h.eql?(x: [h])
end

ruby_version_is "3.1" do
it "allows ommiting values" do
a = 1
b = 2

eval('{a:, b:}.should == { a: 1, b: 2 }')
end
end
end
15 changes: 15 additions & 0 deletions language/keyword_arguments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,21 @@ def m(*args)
m({a: 1}).should == [[{a: 1}], {}]
end

ruby_version_is "3.1" do
describe "omitted values" do
it "accepts short notation 'key' for 'key: value' syntax" do
def m(a:, b:)
[a, b]
end

a = 1
b = 2

eval('m(a:, b:).should == [1, 2]')
end
end
end

ruby_version_is "3.2" do
it "does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" do
class << self
Expand Down

0 comments on commit fb95741

Please sign in to comment.