代码之家  ›  专栏  ›  技术社区  ›  Rodrigue

相当于Python的Ruby\uuu main\uuuuuu[duplicate]

  •  11
  • Rodrigue  · 技术社区  · 14 年前

    如果在ruby文件中定义如下函数:

    def tell_the_truth()
        puts "truth"
    end
    

    if __name__ == "__main__":
        tell_the_truth()
    

    是简单地调用文件中的函数吗?

    tell_the_truth
    
    2 回复  |  直到 12 年前
        1
  •  25
  •   robert vano    14 年前

    我相信这会奏效:

    if __FILE__ == $0
        tell_the_truth()
    end
    
        2
  •  1
  •   Uladzimir    9 年前
    if __FILE__ == $PROGRAM_NAME
        tell_the_truth()
    end