Ruby/Language Basics/Ruby Commandline

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

create a basic Ruby script called debugtest.rb:

i = 1
j = 0
until i > 1000000
  i *= 2
  j += 1
end
puts "i = #{i}, j = #{j}"
# run as following
# ruby -r debug debugtest.rb



Running the Ruby Interpreter

Usage:
ruby [switches] [--] [program filename] [arguments]
 
Switches (or command-line options):
 
-0[ octal]      Specify a record separator (\0 if no argument).
-a              Autosplit mode with -n or -p (splits $_ into $F).
-c              Check syntax only.
-C directory    cd to directory before executing your script or program.
-d              Set debugging flags (set predefined variable $DEBUG to true).
-e " command"   Execute one line of script. Several -es allowed. Omit [program filename].
-F pattern      split( ) pattern for autosplit (-a).
-i[ extension]  Edit ARGV files in place (make backup if extension supplied).
-I directory    Specify $LOAD_PATH (predefined variable) directory; may be used more than once.
-K kcode        Specify the character set. See Table 16.
-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.
-r library      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]      Turn on tainting checks.
-v              Print version number, then turn on verbose mode (compare --version).
-w              Turn warnings on for your script or program.
-W[ level]      Set warning level: 0=silence, 1=medium, and 2=verbose (default).
-x[ directory]  Strip off text before #! shebang line, and optionally cd to directory.
--copyright     Print the copyright.
--version       Print the version (compare -v).



type a command to check the version of Ruby (this works on Unix/Linux and Windows):

$ ruby -v
 
# or:
$ ruby --version