Skip to content

Commit 56b40b0

Browse files
paracycleandrykonchin
authored andcommitted
Start handling &nil in method parameters
Similar to `:nokey` for `**nil` declaring methods/procs, a method/proc with a `&nil` declaration will return a `:noblock` entry in the parameters array.
1 parent 422819c commit 56b40b0

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

core/method/parameters_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def one_splat_one_block(*args, &block)
2222
local_is_not_parameter = {}
2323
end
2424

25+
ruby_version_is "4.1" do
26+
eval <<-RUBY
27+
def one_noblock(&nil); end
28+
RUBY
29+
end
30+
2531
def forward_parameters(...) end
2632

2733
def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
@@ -187,6 +193,13 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
187193
m.parameters.should == [[:nokey]]
188194
end
189195

196+
ruby_version_is "4.1" do
197+
it "returns [[:noblock]] for a method with a single &nil parameter" do
198+
m = MethodSpecs::Methods.instance_method(:one_noblock)
199+
m.parameters.should == [[:noblock]]
200+
end
201+
end
202+
190203
it "works with ->(){} as the value of an optional argument" do
191204
m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby)
192205
m.parameters.should == [[:opt,:a]]

core/proc/parameters_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,12 @@
172172
eval("lambda { it }").parameters.should == [[:req]]
173173
end
174174
end
175+
176+
ruby_version_is "4.1" do
177+
it "returns :noblock for &nil parameter" do
178+
eval <<~RUBY
179+
proc { |&nil| }.parameters.should == [[:noblock]]
180+
RUBY
181+
end
182+
end
175183
end

language/block_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def o.it
11111111
end
11121112
end
11131113

1114-
ruby_version_is "3.4" do
1114+
ruby_version_is "4.1" do
11151115
it "works alongside disallowed block argument" do
11161116
no_block = eval <<-EOF
11171117
proc {|arg1, &nil| arg1}

language/method_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ def m(a, b = nil, c = nil, d, e: nil, **f)
11281128
result.should == [1, nil, nil, {foo: :bar}, nil, {}]
11291129
end
11301130

1131-
ruby_version_is "3.4" do
1131+
ruby_version_is "4.1" do
11321132
evaluate <<-ruby do
11331133
def m(a, &nil); a end;
11341134
ruby

0 commit comments

Comments
 (0)