gpt4 book ai didi

ruby - 用于测试的 ruby​​ 模块中的重写方法?

转载 作者:太空宇宙 更新时间:2023-11-03 18:01:32 25 4
gpt4 key购买 nike

如何覆盖模块中的方法?

最佳答案

稍后将您的新方法放入代码中。例如,如果这是模块 (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

关于ruby - 用于测试的 ruby​​ 模块中的重写方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3230285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com