【问题标题】:YARD: Document non-useful or unintentional return场:记录无用或无意退货
【发布时间】:2017-10-13 08:02:47
【问题描述】:

我有一个像这样的不纯函数:

# Impure function: Sets the status for a report_schedule, uses last_sent to
# calculate status
# @param report_schedule [Hash]
# @return [String] Non-useful: value of last_sent that was set
def self.set_report_schedule_status(report_schedule)
  # Some logic that calculates status of report_schedule
  report_schedule['status'] = status
  report_schedule['last_sent'] = Time.now.to_s
end

我想要这个函数做的是设置statuslast_sent,但是这里的副作用是它返回Time.now.to_s。有没有适当的方法来记录这一点? 或者是我的函数定义错误还是应该以 return nil 结尾。

【问题讨论】:

    标签: ruby documentation yard


    【解决方案1】:

    应该只是添加return nil

    Ruby 自动将返回附加到方法中执行的最后一项操作

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      相关资源
      最近更新 更多