Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3.1: Omit values in hashs and kwargs #951

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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