From c7ed8478a031d0df346d222495f4b4bbb298523b Mon Sep 17 00:00:00 2001 From: Eduardo Hernandez Date: Fri, 7 Oct 2022 22:17:44 -0500 Subject: [PATCH] Ruby 3.1: Omit values in hashs and kwargs Values in Hash literals and keyword arguments can be omitted. - See: [Feature #14579](https://bugs.ruby-lang.org/issues/14579) - From: https://github.com/ruby/spec/issues/923 --- core/hash/hash_spec.rb | 9 +++++++++ language/keyword_arguments_spec.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/core/hash/hash_spec.rb b/core/hash/hash_spec.rb index 3649d4d8de..2ccb483120 100644 --- a/core/hash/hash_spec.rb +++ b/core/hash/hash_spec.rb @@ -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 diff --git a/language/keyword_arguments_spec.rb b/language/keyword_arguments_spec.rb index 8771c5806c..c47b7b0ae9 100644 --- a/language/keyword_arguments_spec.rb +++ b/language/keyword_arguments_spec.rb @@ -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