【问题标题】:Overriding method in ruby module for testing?ruby 模块中的覆盖方法进行测试?
【发布时间】:2011-03-14 21:41:01
【问题描述】:

如何覆盖模块中的方法?

【问题讨论】:

标签: ruby unit-testing


【解决方案1】:

稍后将您的新方法放入代码中。例如,如果这是模块(somefile.rb):

module M
  def some_method
    # ...
  end

  def get_time
    time = Time.new
    return time
  end
end

把这个放到需要模块的文件中:

require "some_module"

module M
  def get_time
    time = Time.parse("07/09/10 21:22")
    return time
  end
end

【讨论】:

  • @Mo:是的。这个额外的句子是用内容填充评论,这样堆栈溢出就不会因为简短的评论而生气。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-03
  • 2019-08-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多