2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Ruby】main 関数を記述する方法

Posted at

rubyにおける main 関数の書き方

Rubyにおいて直接スクリプトファイルとして呼び出すときだけ実行される
main 関数を記述する方法について。

結論:FILE 変数を使用すればよい。

if __FILE__ == $0
 # main method
end

上記の様に記述すればモジュールとしてインポートされる時には実行されない。
直接スクリプトファイルとして呼び出すときだけ実行される main 関数の様な動作をする。

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?