简体   繁体   English

坚持使用 rdoc:有什么方法可以为 call-seq 添加缩进?

[英]Stuck with rdoc: Any way to add indentation to call-seq?

I know I should use YARD.我知道我应该使用 YARD。 Not an option in this environment.在这种环境中不是一个选项。

So I'm using rdoc and call-seq is generally been great, but I want to add indentation for a call-seq that is always used in a block/yield style, something like:所以我使用 rdoc 并且 call-seq 通常很棒,但是我想为始终以块/yield 样式使用的 call-seq 添加缩进,例如:

call-seq:
    someFunc {
        example1(..)
        example2(..)
    }

But call-seq: removes any indentation and it becomes:但是 call-seq: 删除任何缩进,它变成:

    someFunc {
    example1(..)
    example2(..)
    }

Which is sad.这是可悲的。 I know I could use a separate code block as an example, but this is really part of the general API for how this should be called, and it would be nice if I could use call-seq (instead of the ugly inverted colors of a code block).我知道我可以使用单独的代码块作为示例,但这实际上是关于如何调用它的通用 API 的一部分,如果我可以使用 call-seq(而不是丑陋的反转颜色)代码块)。

I am guessing this isn't possible with the limitations of rdoc, but I thought I'd ask.我猜这在 rdoc 的限制下是不可能的,但我想我会问。 Any thoughts?有什么想法吗?

I think you are confused about what the purpose of the calling sequence is, but the name unfortunately is really confusing.我认为您对调用序列的目的感到困惑,但不幸的,名称确实令人困惑。 Normally, I would assume that it was designed by a non-native speaker, but if I remember my history correctly, RDoc was designed by David Thomas and Andy Hunt for their book Programming Ruby in 2000.通常,我会假设它是由非母语人士设计的,但如果我没有记错我的历史,RDoc 是由 David Thomas 和 Andy Hunt 在 2000 年为他们的书Programming Ruby 设计的。

Anyway, calling sequence is not for documenting a sequence of calls , as one might surmise, ie it is not for documenting multiple lines of code.不管怎样,调用顺序不是记录调用序列,如人们所猜测的,即它不是用于记录的多行代码。

It is for documenting what we could all in other languages multiple overloads of the method.它用于记录我们可以在其他语言中对方法的多次重载 Note that the syntax that is used for each overload is not even legal Ruby syntax (because of the ), so treating it as executable code that is to be indented does not make much sense:请注意,用于每个重载的语法甚至不是合法的 Ruby 语法(因为 ),因此将其视为要缩进的可执行代码并没有多大意义:

  • inject(initial, sym)obj inject(initial, sym)obj
  • inject(sym)obj inject(sym)obj
  • inject(initial) { |memo, obj| block } inject(initial) { |memo, obj| block }obj inject(initial) { |memo, obj| block }obj
  • inject { |memo, obj| block } inject { |memo, obj| block }obj inject { |memo, obj| block }obj

What this tells us is that the Enumerable#inject method has four different "overloads", 2×2 combinations: with or without initial value and specifying the binary operation either as a block or as a Symbol .这告诉我们Enumerable#inject方法有四种不同的“重载”,2×2 组合:有或没有初始值,并将二元运算指定为块或Symbol

Hence why it is not possible to format code inside the calling sequence.这就是为什么不能在调用序列中格式化代码的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM