Bug #9242

Rdoc detection of aliases

Added by Marc-Andre Lafortune 4 months ago. Updated 2 months ago.

[ruby-core:59060]
Status:Assigned
Priority:Normal
Assignee:Eric Hodel
Category:lib
Target version:next minor
ruby -v:2.1.0 preview Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN

Description

The online doc appears to be making bad detection of aliases.

For example, Array#map and Array#collect are not marked as aliases (on either ruby-doc.org or docs.ruby-lang.org)

On the other hand, when aliases are detected, the generated method interface and the name of the method it is aliases to are always the same for both methods.

For example, the doc for Array#findindex says it is an alias to findindex and has interface showing index (again on both sites), e.g. http://docs.ruby-lang.org/en/2.0.0/Array.html#method-i-find_index

It might also be a good idea to always have doc examples using both forms in case of aliases.

History

#1 Updated by Hans Mackowiak 4 months ago

Array#map and Array#collect are not real aliases
both methods are defined with the excact same method body function but both are not calling each other,
so changeing one method doe not break the other

#2 Updated by Zachary Scott 4 months ago

  • Status changed from Open to Assigned
  • Assignee changed from Eric Hodel to Zachary Scott

Alias detection was updated in the pre-release of RDoc 4.1.0, can you try to test it?

If it's these methods are using the same method, we can easily fix this by adding another signature to the call-seq example. What do you think?

#3 Updated by Eric Hodel 4 months ago

  • Assignee changed from Zachary Scott to Eric Hodel
  • Target version set to next minor

As Hanmac noted, they aren't real aliases:

$ grep rbarycollect array.c
rbarycollect(VALUE ary)
rbarycollectbang(VALUE ary)
rb
definemethod(rbcArray, "collect", rbarycollect, 0);
rbdefinemethod(rbcArray, "collect!", rbarycollectbang, 0);
rbdefinemethod(rbcArray, "map", rbarycollect, 0);
rb
definemethod(rbcArray, "map!", rbarycollect_bang, 0);

But I guess this is for performance reasons (can someone confirm?). I suppose RDoc should treat these as aliases.

#4 Updated by Marc-Andre Lafortune 4 months ago

There really shouldn't be a difference between using rb_define_alias and using the same rb_define_method.

In Ruby, Array.instance_method(:map) == Array.instance_method(:collect) returns true (even when not defined using rbdefinealias), and they should be treated as aliases.

Moreover, the problem isn't there, since Array#findindex and index are not defined using rbdefine_alias either but the generated doc sees them as aliases.

#5 Updated by Zachary Scott 2 months ago

  • Category changed from doc to lib

Also available in: Atom PDF