Skip to content

Commit

Permalink
Add test to cover assigning a numbered parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Oct 17, 2021
1 parent a498687 commit 64c1d2e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spec/ruby/language/numbered_parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@
-> { eval("['a'].map { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
end

describe "assigning to a numbered parameter" do
ruby_version_is '2.7'...'3.0' do
it "warns" do
-> { eval("proc { _1 = 0 }") }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/)
end
end

ruby_version_is '3.0' do
it "raises SyntaxError" do
-> { eval("proc { _1 = 0 }") }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
end
end
end

it "affects block arity" do
-> { _1 }.arity.should == 1
-> { _2 }.arity.should == 2
Expand Down

0 comments on commit 64c1d2e

Please sign in to comment.