gpt4 book ai didi

ruby - 如何确定 ruby​​ 文件用作 lib 还是脚本?

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

我写了一个可以用作库的 ruby​​ 文件。但是为了测试它,我也写了一些测试数据。

例如:

class Checker
do some thing
end

# if this file is used as a library, I don't want following code executed
checker = Checker.new
checker.dosomething

我知道有一种方法可以确定文件是否用作库,但我现在不记得了。就像:

if ???=__FILE__
checker = Checker.new
checker.dosomething
end

有人知道吗?提前致谢

最佳答案

也许您想到的是 $0 == __FILE__

尽管其他人必须确认这是否适用于所有情况。

关于ruby - 如何确定 ruby​​ 文件用作 lib 还是脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3218340/

25 4 0
文章推荐: c# - PDF -Adobe 数字版
文章推荐: python - 在 Spyder 中下载和导入模块的解决方法?
文章推荐: c# - 在 Visual Studio 2008 中将项目更改为 Web 应用程序
文章推荐: jquery - 单击链接标记时在
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com