1

私はプロジェクトを文書化しており、本質的に次のようなものがあります。

def foo
  return bar(__method__)
end

def bar (method)
 return method.to_s + 'somestring'
end

私は、fooを実装した方法と同様の多数のメソッドを設定していますが、それらはbarの戻り値を返しています。例は次のとおりです。

# The descriptions for foo0...
# @return [String] the method name concatenated with somestring
def foo0
  return bar(__method__)
end
# The descriptions for foo1...
# @return [String] the method name concatenated with somestring
def foo1
  return bar(__method__)
end

# The descriptions for bar...
# @return [String] the method name concatenated with somestring
def bar (method)
 return method.to_s + 'somestring'
end

barしかし、整数に戻るものを変更すると、ドキュメントが正しくなくなります。YARDでDSLを文書化することはよく知っていますが、別のメソッドを記述するときに#bar@return.type、メソッドのリターンのリターンタイプをどのように指定するのですか。bar私が言及しているものの例は次のとおりです。

# The descriptions for foo0...
# @return [#bar@return.type] the method name concatenated with somestring
def foo0
  return bar(__method__)
end
# The descriptions for foo1...
# @return [#bar@return.type] the method name concatenated with somestring
def foo1
  return bar(__method__)
end

# The descriptions for bar...
# @return [String] the method name concatenated with somestring
def bar (method)
 return method.to_s + 'somestring'
end

最終的に私が達成しようとしているのは、別のメソッドが定義されているものに依存する戻り型のような絶対値を定義する必要なしに、コードを文書化することです。

更新:呼び出して、リターンまたはメソッドをメソッドと同じよう# @return (see #bar)にリストすることができることを発見しましたが、返されるタイプを簡単に取得する方法や、リターンの説明をオーバーロードする方法を判断できません。のカスタム説明付き。foobarbarfoo

4

1 に答える 1

1

あなたが発見したように、タグを #bar verbatim から他のドキュメント文字列@return (see #bar)にコピーするために使用する必要があります。@return注: 説明テキストもコピーされます。メソッドの型を単に補間する方法はありません。ただし、特定の例では必要ないようです。

于 2012-04-27T04:48:43.770 に答える