Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果在一个 ruby 文件中我定义了一个这样的函数:
def tell_the_truth() puts "truth" end
有没有相当于 python 的 main 的?
if __name__ == "__main__": tell_the_truth()
是简单地调用文件内的函数吗?
tell_the_truth
我相信这会奏效:
if __FILE__ == $0 tell_the_truth() end
if __FILE__ == $PROGRAM_NAME tell_the_truth() end