2011-06-15 54 views
3

我正在记录一些ruby代码。我们有两个类都有一个称为“主机”的方法。链接到一个不同类中的同名方法(Rdoc)

在这些类中的一个中,该方法需要一些特殊的注释。在其他班级中,我想参考第一堂课,并将该参考链接指向它。

通常在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方法。

谢谢!

回答

2

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

下面的例子,你正在描述什么。

class A 
    # first method 
    def a 
    end 
end 

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

Hmm nope ...当我插入注释“#class :: SubClass#host”时,链接仍然指向当前类的宿主方法。虽然谢谢! – Ziggy 2011-06-29 05:22:48

+0

我看不出为什么这不起作用。你能否提供一个简短的例子,这是行不通的?也许这有助于发现错误。 – 2011-06-29 08:23:00

相关问题