gpt4 book ai didi

ruby - 链接到不同类中的同名方法 (Rdoc)

转载 作者:数据小太阳 更新时间:2023-10-29 08:06:02 27 4
gpt4 key购买 nike

我现在正在记录一些 ruby​​ 代码。我们有两个类都有一个名为“host”的方法。

在其中一个类中,该方法需要一些特殊注释。在另一个类中,我想引用第一个类,并将该引用作为指向它的链接。

通常在 rdoc 中,键入一个方法的名称就足以生成一个链接。在这种情况下,即使我写出 Class::SubClass.host 链接仍然坚持指向当前类中的方法。

有哪位 rdoc 高手知道如何做到这一点?

这是 FakeTown::Api 中的一个例子,我想链接到 RealTown::Api 的方法 #host :

# Returns the host as defined in config.yml under the heading "url".
#
# It appears as though this method is no longer in use, as
# features/support/vcr_config.rb contains its own method
# by the same name which directly references RealTown::Api#url
def host
uri = URI.parse url
uri.host
end

rdoc 生成的链接毫无帮助地直接链接回本文档中的 #host 方法。

谢谢!

最佳答案

您可能想链接到实例方法,而不是类方法。 Class::SubClass#host 应该可以工作。

下面的例子就是你所描述的。

class A
# first method
def a
end
end

class B
# second method linking to A#a
def a
end
end

关于ruby - 链接到不同类中的同名方法 (Rdoc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6365047/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com