コマンドラインオプション

コマンドラインオプション 動作
-h
--help
コマンドラインオプションのヘルプを表示
-v
--version
バージョンを表示
-c 文法が正しいか確認し、正しければSyntax OKと表示。実行はしない。
-e コマンドラインをスクリプトとして実行
-w 冗長モードで実行。警告が表示される。
-W0
-W1
-W2
-W
警告を表示する
-l ファイルをロードするパスを指定
-r 実行前に指定したファイルを実行
-d デバッグモードで実行

-h, --help

ruby -h
# Usage: ruby [switches] [--] [programfile] [arguments]
#   -0[octal]       specify record separator (\0, if no argument)
#   -a              autosplit mode with -n or -p (splits $_ into $F)
#   -c              check syntax only
#   -Cdirectory     cd to directory before executing your script
#   -d              set debugging flags (set $DEBUG to true)
#   -e 'command'    one line of script. Several -e's allowed. Omit [programfile]
#   -Eex[:in]       specify the default external and internal character encodings
#   -Fpattern       split() pattern for autosplit (-a)
#   -i[extension]   edit ARGV files in place (make backup if extension supplied)
#   -Idirectory     specify $LOAD_PATH directory (may be used more than once)
#   -l              enable line ending processing
#   -n              assume 'while gets(); ... end' loop around your script
#   -p              assume loop like -n but print line also like sed
#   -rlibrary       require the library before executing your script
#   -s              enable some switch parsing for switches after script name
#   -S              look for the script using PATH environment variable
#   -T[level=1]     turn on tainting checks
#   -v              print the version number, then turn on verbose mode
#   -w              turn warnings on for your script
#   -W[level=2]     set warning level; 0=silence, 1=medium, 2=verbose
#   -x[directory]   strip off text before #!ruby line and perhaps cd to directory
#   --jit           enable JIT with default options (experimental)
#   --jit-[option]  enable JIT with an option (experimental)
#   -h              show this message, --help for more info

-v, --version

ruby -v
# ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]

-c

以下のプログラムhello.rbを指定する。

puts "Hello, world!!"
ruby -c hello.rb
# Syntax OK

-e

ruby -e "puts \"Hello, world\!\""
# Hello, world!

-w, -W0, -W1, -W2, -W

以下のプログラムhoge.rbを実行する。

puts "hogehoge" if 1
ruby -w hoge.rb
# hoge.rb:1: warning: literal in condition
# hogehoge

正当なCSSです!