开发者

Ruby equivalent to Python __main__ [duplicate]

This question already has answers here: `if __name__ == '__main__&#开发者_StackOverflow中文版39;` equivalent in Ruby (3 answers) Closed 6 years ago.

If in a ruby file I define a function like so:

def tell_the_truth()
    puts "truth"
end

is there an equivalent to python's main?

if __name__ == "__main__":
    tell_the_truth()

Is it to simply call the function inside the file?

tell_the_truth


I believe this will work:

if __FILE__ == $0
    tell_the_truth()
end


if __FILE__ == $PROGRAM_NAME
    tell_the_truth()
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜