【问题标题】:Ruby: How to correctly and efficiently write comments?Ruby:如何正确高效地写评论?
【发布时间】:2016-06-25 16:03:26
【问题描述】:

我正在阅读用于 Ruby 的 Mailchimp API 包装器的代码,名为 Mailchimp-Api-Ruby。我将在我的问题下方发布一个 sn-p。

除了代码之外,cmets 引起了我的注意。发生这种情况有两个原因:

  1. cmets 似乎有一个样式约定,特别是对于调用外部 api 的方法。我知道 Ruby 样式约定,例如来自 B.Batsov 的 this one,其中也有一个关于 cmets 的部分。但是这部分内容很短,甚至与我在研究的代码中看到的内容都不相近。
  2. cmets 构成了大部分文本,并提供有关 参数和返回值,包括描述性文本。

我的问题是,是否有关于如何呈现所有这些信息以及从何处获取这些信息的约定?这是手写的还是有办法从某个地方提取出来的?

这是我正在研究的代码的 sn-p:

# Get the content (both html and text) for a campaign either as it would appear in the campaign archive or as the raw, original content # @param [String] cid the campaign id to get content for (can be gathered using campaigns/list()) # @param [Hash] options various options to control this call # - [String] view optional one of "archive" (default), "preview" (like our popup-preview) or "raw" # - [Hash] email optional if provided, view is "archive" or "preview", the campaign's list still exists, and the requested record is subscribed to the list. the returned content will be populated with member data populated. a struct with one of the following keys - failing to provide anything will produce an error relating to the email address. If multiple keys are provided, the first one from the following list that we find will be used, the rest will be ignored. # - [String] email an email address # - [String] euid the unique id for an email address (not list related) - the email "id" returned from listMemberInfo, Webhooks, Campaigns, etc. # - [String] leid the list email id (previously called web_id) for a list-member-info type call. this doesn't change when the email address changes # @return [Hash] containing all content for the campaign # - [String] html The HTML content used for the campaign with merge tags intact # - [String] text The Text content used for the campaign with merge tags intact def content(cid, options=[]) _params = {:cid => cid, :options => options} return @master.call 'campaigns/content', _params end

【问题讨论】:

    标签: ruby api comments


    【解决方案1】:

    这是yard format 中的文档。

    ✓ http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md

    这是手写的还是有办法从某个地方提取出来的?

    它是手写的,因为我几乎无法想象它可以从哪里提取出来。

    【讨论】:

    • 感谢您的帮助。由于 cmets 中的信息非常示意性,并且描述文本来自 API 的文档,我认为可能有一种方法可以从 API 中获取它?如果可以在原始 API 文档中看到,为什么有人会费力地复制和粘贴所有这些信息(这可能会产生一些错误)?
    • 您在原始 API 文档中看到的内容,由 yard 这些 cmets 生成
    • 注意:一些IDE,例如Rubymine,可以自动创建部分YARD文档块。但其中大部分,尤其是参数/返回值类型,必须手动输入,因为它们无法从代码中推断出来。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 2014-11-18
    相关资源
    最近更新 更多