Run a Ruby library from the command-line

前端 未结 3 525
小蘑菇
小蘑菇 2020-12-29 08:00

I\'ve just learned the basics of Ruby after being very happy with Python for several years (I\'m still using Python for some things), but I\'d like to know if there\'s an id

3条回答
  •  鱼传尺愫
    2020-12-29 08:53

    While

    if __FILE__ == $0
      Foo.run
    end
    

    is the common approach, I'm currently using

    if File.identical?(__FILE__, $0)
      Foo.run
    end
    

    because programs like ruby-prof can make $0 not equal __FILE__ even when you use --replace-progname.

提交回复
热议问题