diff options
author | Jeremy Evans <[email protected]> | 2019-09-10 16:17:09 -0700 |
---|---|---|
committer | aycabta <[email protected]> | 2020-05-24 23:47:24 +0900 |
commit | 7e7981c84f8cd3225b5e915cba2281869a08b784 (patch) | |
tree | c18b72aca8c83a5f976399be5f6df9aadf00bc96 /lib/rdoc/any_method.rb | |
parent | f52a4690f8fbd495e8517178a0bf95c69ccea47c (diff) |
[ruby/rdoc] Treat multiple Ruby methods calling the same C method as aliases
Previously, only calls to rb_define_alias were treated as aliases.
This treats calls to rb_define_method with the same C function as
aliases, with the first function defined being the primary method.
This move the dedup code from the C parser to AnyMethod, and has
AnyMethod look in its aliases to find the call_seq.
Switch the deduplication code to remove lines matching one of the
other aliases, instead of only keeping lines matching the current
alias. The previous approach could eliminate all call_seq lines
in cases where no line matched. This was necessary to pass
tests when call_seq does deduplication by default.
The only change to the darkfish template is to not perform
unnecessary work by deduplicating twice.
https://github.com/ruby/rdoc/commit/0ead78616b
Diffstat (limited to 'lib/rdoc/any_method.rb')
-rw-r--r-- | lib/rdoc/any_method.rb | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb index 9b0d309653..562e68461c 100644 --- a/lib/rdoc/any_method.rb +++ b/lib/rdoc/any_method.rb @@ -26,12 +26,6 @@ class RDoc::AnyMethod < RDoc::MethodAttr attr_accessor :c_function - ## - # Different ways to call this method - - attr_reader :call_seq - - ## # Parameters for this method attr_accessor :params @@ -94,6 +88,19 @@ class RDoc::AnyMethod < RDoc::MethodAttr end ## + # Different ways to call this method + + def call_seq + unless call_seq = _call_seq + call_seq = is_alias_for._call_seq if is_alias_for + end + + return unless call_seq + + deduplicate_call_seq(call_seq) + end + + ## # Sets the different ways you can call this method. If an empty +call_seq+ # is given nil is assumed. # @@ -312,5 +319,43 @@ class RDoc::AnyMethod < RDoc::MethodAttr @superclass_method end -end + protected + + ## + # call_seq without deduplication and alias lookup. + + def _call_seq + @call_seq if defined?(@call_seq) && @call_seq + end + + private + + ## + # call_seq with alias examples information removed, if this + # method is an alias method. + + def deduplicate_call_seq(call_seq) + return call_seq unless is_alias_for || !aliases.empty? + + method_name = self.name + method_name = method_name[0, 1] if method_name =~ /\A\[/ + entries = call_seq.split "\n" + + ignore = aliases.map(&:name) + if is_alias_for + ignore << is_alias_for.name + ignore.concat is_alias_for.aliases.map(&:name) + end + ignore.map! { |n| n =~ /\A\[/ ? n[0, 1] : n} + ignore.delete(method_name) + ignore = Regexp.union(ignore) + + matching = entries.reject do |entry| + entry =~ /^\w*\.?#{ignore}/ or + entry =~ /\s#{ignore}\s/ + end + + matching.join "\n" + end +end |