Skip to content

Commit

Permalink
Merge pull request #1590 from pvande/patch-1
Browse files Browse the repository at this point in the history
Update signature handling in @overload
  • Loading branch information
lsegal authored Oct 11, 2024
2 parents e96ae99 + 7641cc5 commit 3c14200
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/yard/tags/overload_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def parse_signature
args = YARD::Handlers::Ruby::Legacy::Base.new(nil, nil).send(:tokval_list, toks, :all)
args = args.map do |a|
k, v = *a.split(/:|=/, 2)
[k.strip.to_s + (a[k.size, 1] == ':' ? ':' : ''), (v ? v.strip : nil)]
v.strip! if v
[k.strip.to_s + (a[k.size, 1] == ':' ? ':' : ''), (v && v.empty? ? nil : v)]
end if args
@name = meth.to_sym
@parameters = args
Expand Down
15 changes: 15 additions & 0 deletions spec/tags/overload_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ def bar(a, b = 1, &block)
tag = Tags::OverloadTag.new(:overload, "default")
expect(tag.signature).to eq "default"
end

it "properly handles complex signatures" do
tag = Tags::OverloadTag.new(:overload, "foo(a, b = 1, *c, d, e:, f: 2, g:, **rest, &block)")
expect(tag.parameters).to eq [
['a', nil],
['b', "1"],
['*c', nil],
['d', nil],
['e:', nil],
['f:', "2"],
['g:', nil],
['**rest', nil],
['&block', nil],
]
end
end

0 comments on commit 3c14200

Please sign in to comment.