mdoc'ify.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2002-12-30 19:56:06 +00:00
parent c2e3d3971b
commit 378a6bdea5
2 changed files with 273 additions and 254 deletions

View File

@ -1,3 +1,7 @@
Tue Dec 31 04:49:51 2002 Akinori MUSHA <knu@iDaemons.org>
* ruby.1: mdoc'ify.
Tue Dec 31 01:30:29 2002 WATANABE Hirofumi <eban@ruby-lang.org> Tue Dec 31 01:30:29 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* parse.y (yylex): do not accept " __END__\n". ([ruby-dev:19245]) * parse.y (yylex): do not accept " __END__\n". ([ruby-dev:19245])

523
ruby.1
View File

@ -1,291 +1,306 @@
.\"Ruby is copyrighted by Yukihiro Matsumoto <matz@netlab.jp>. .\"Ruby is copyrighted by Yukihiro Matsumoto <matz@netlab.jp>.
.na .Dd December 31, 2002
.TH RUBY 1 "ruby 1.6" "2000-09-11" "Ruby Programmers Reference Guide" .Dt RUBY(1) "" "Ruby Programmers Reference Guide"
.SH NAME .\".Dt RUBY 1
ruby - Interpreted object-oriented scripting language .Os UNIX
.SH SYNOPSIS .Sh NAME
.B ruby \c .Nm ruby
[ \c .Nd Interpreted object-oriented scripting language
.BI --version \c .Sh SYNOPSIS
] [ \c .Nm
.BI -c \c .Op Fl -copyright
] [ \c .Op Fl -version
.BI -w \c .Op Fl Sacdlnpswvy
] [ \c .Op Fl 0 Ns Op Ar octal
.BI -d \c .Op Fl C Ar directory
] [ \c .Op Fl F Ar pattern
.BI -l \c .Op Fl I Ar directory
] .Op Fl K Ar c
[ \c .Op Fl T Ns Op Ar level
.BI -p \c .Op Fl e Ar command
] [ \c .Op Fl i Ns Op Ar extension
.BI -n \c .Op Fl r Ar library
] [ \c .Op Fl x Ns Op Ar directory
.BI -a \c .Op Fl -
] [ \c .Op Ar program_file
.BI -s \c .Op Ar argument ...
] [ \c .Sh DESCRIPTION
.BI -0 "[octal]"\c
]
[ \c
.BI -K "c"\c
] [ \c
.BI -e "command"\c
] [ \c
.BI -F "pattern"\c
]
[ \c
.BI -i "[extension]"\c
] [ \c
.BI -I "dir"\c
] [ \c
.BI -r "library"\c
]
[ \c
.BI -S \c
] [ \c
.BI -v \c
] [ \c
.BI -x "[directory]"\c
] [ \c
.BI -C "directory"\c
]
[ \c
.BI -y \c
] [ \c
.BI -- \c
] [ programfile ] [ argument ] ...
.SH PREFACE
Ruby is an interpreted scripting language for quick and easy Ruby is an interpreted scripting language for quick and easy
object-oriented programming. It has many features to process text object-oriented programming. It has many features to process text
files and to do system management tasks (as in Perl). It is simple, files and to do system management tasks (as in Perl). It is simple,
straight-forward, and extensible. straight-forward, and extensible.
.PP .Pp
If you want a language for easy object-oriented programming, or you If you want a language for easy object-oriented programming, or you
don't like the Perl ugliness, or you do like the concept of lisp, but don't like the Perl ugliness, or you do like the concept of LISP, but
don't like too much parentheses, Ruby may be the language of your don't like too much parentheses, Ruby may be the language of your
choice. choice.
.SH DESCRIPTION .Sh FEATURES
Ruby's features are as follows: Ruby's features are as follows:
.TP .Bl -tag -width "12"
.B "\(bu Interpretive" .It Sy "Interpretive"
Ruby is an interpreted language, so you don't have to recompile Ruby is an interpreted language, so you don't have to recompile
programs written in Ruby to execute them. programs written in Ruby to execute them.
.TP .Pp
.B "\(bu Variables have no type (dynamic typing)" .It Sy "Variables have no type (dynamic typing)"
Variables in Ruby can contain data of any type. You don't have to Variables in Ruby can contain data of any type. You don't have to
worry about variable typing. Consequently, it has a weaker compile worry about variable typing. Consequently, it has a weaker compile
time check. time check.
.TP .Pp
.B "\(bu No declaration needed" .It Sy "No declaration needed"
You can use variables in your Ruby programs without any declarations. You can use variables in your Ruby programs without any declarations.
Variable names denote their scope, local, global, instance, etc. Variable names denote their scope, local, global, instance, etc.
.TP .Pp
.B "\(bu Simple syntax" .It Sy "Simple syntax"
Ruby has a simple syntax influenced slightly from Eiffel. Ruby has a simple syntax influenced slightly from Eiffel.
.TP .Pp
.B "\(bu No user-level memory management" .It Sy "No user-level memory management"
Ruby has automatic memory management. Objects no longer Ruby has automatic memory management. Objects no longer referenced
referenced from anywhere are automatically collected by the from anywhere are automatically collected by the garbage collector
garbage collector built into the interpreter. built into the interpreter.
.TP .Pp
.B "\(bu Everything is an object" .It Sy "Everything is an object"
Ruby is the purely object-oriented language, and was so since its Ruby is the purely object-oriented language, and was so since its
creation. Even such basic data as integers are seen as objects. creation. Even such basic data as integers are seen as objects.
.TP .Pp
.B "\(bu Class, inheritance, methods" .It Sy "Class, inheritance, and methods"
Of course, as an object-oriented language, Ruby has such basic Of course, as an object-oriented language, Ruby has such basic
features like classes, inheritance, and methods. features like classes, inheritance, and methods.
.TP .Pp
.B "\(bu Singleton methods" .It Sy "Singleton methods"
Ruby has the ability to define methods for certain objects. For Ruby has the ability to define methods for certain objects. For
example, you can define a press-button action for certain widget by example, you can define a press-button action for certain widget by
defining a singleton method for the button. Or, you can make up your defining a singleton method for the button. Or, you can make up your
own prototype based object system using singleton methods, if you want own prototype based object system using singleton methods, if you want
to. to.
.TP .Pp
.B "\(bu Mix-in by modules" .It Sy "Mix-in by modules"
Ruby intentionally does not have the multiple inheritance as it is a Ruby intentionally does not have the multiple inheritance as it is a
source of confusion. Instead, Ruby has the ability to share source of confusion. Instead, Ruby has the ability to share
implementations across the inheritance tree. This is often called implementations across the inheritance tree. This is often called
`Mix-in'. .Sq Mix-in .
.TP .Pp
.B "\(bu Iterators" .It Sy "Iterators"
Ruby has iterators for loop abstraction. Ruby has iterators for loop abstraction.
.TP .Pp
.B "\(bu Closures" .It Sy "Closures"
In Ruby, you can objectify the procedure. In Ruby, you can objectify the procedure.
.TP .Pp
.B "\(bu Text processing and regular expression" .It Sy "Text processing and regular expression"
Ruby has a bunch of text processing features like in Perl. Ruby has a bunch of text processing features like in Perl.
.TP .Pp
.B "\(bu Bignums" .It Sy "Bignums"
With built-in bignums, you can for example calculate factorial(400). With built-in bignums, you can for example calculate factorial(400).
.TP .Pp
.B "\(bu Exception handling" .It Sy "Exception handling"
As in Java(tm). As in Java(tm).
.TP .Pp
.B "\(bu Direct access to the OS" .It Sy "Direct access to the OS"
Ruby can use most UNIX system calls, often used in system programming. Ruby can use most
.TP .Ux
.B "\(bu Dynamic loading" system calls, often used in system programming.
On most UNIX systems, you can load object files into the Ruby .Pp
interpreter on-the-fly. .It Sy "Dynamic loading"
.PP On most
.SH COMMAND LINE OPTIONS .Ux
systems, you can load object files into the Ruby interpreter
on-the-fly.
.Pp
.Sh OPTIONS
Ruby interpreter accepts following command-line options (switches). Ruby interpreter accepts following command-line options (switches).
They are quite similar to those of Perl. They are quite similar to those of
.TP .Xr perl 1 .
.B -0[octal] .Bl -tag -width "12" -compact
specifies the input record separator ($/) as an octal number. If no .Pp
digit is given, the null character is taken as the separator. Other .It Fl -copyright
switches may follow the digits. -00 turns Ruby into paragraph mode. - Prints the copyright notice.
0777 makes Ruby read whole file at once as a single string since there .Pp
is no legal character with that value. .It Fl -version
.TP Prints the version of Ruby interpreter.
.B -a .Pp
turns on auto-split mode when used with -n or -p. In auto-split .It Fl 0 Ns Op Ar octal
mode, Ruby executes (The digit
.nf .Dq zero . )
.ne 1 Specifies the input record separator
\& $F = $_.split .Pf ( Li "$/" )
as an octal number. If no digit is given, the null character is taken
as the separator. Other switches may follow the digits.
.Fl 00
turns Ruby into paragraph mode.
.Fl 0777
makes Ruby read whole file at once as a single string since there is
no legal character with that value.
.Pp
.It Fl C Ar directory
Causes Ruby to switch to the directory.
.Pp
.It Fl F Ar pattern
Specifies input field separator
.Pf ( Li "$;" ) .
.Pp
.It Fl I Ar directory
Used to tell Ruby where to load the library scripts. Directory path
will be added to the load-path variable
.Pf ( Li "$:" ) .
.Pp
.It Fl K Ar kcode
Specifies KANJI (Japanese) encoding.
.Pp
.It Fl S
Makes Ruby use the
.Ev PATH
environment variable to search for script, unless if its name begins
with a slash. This is used to emulate #! on machines that don't
support it, in the following manner:
.Bd -literal -offset indent
#! /usr/local/bin/ruby
# This line makes the next one a comment in ruby \e
exec /usr/local/bin/ruby -S $0 $*
.Ed
.Pp
.It Fl T Ns Op Ar level
Turns on taint checks at the specified level (default 1).
.Pp
.It Fl a
Turns on auto-split mode when used with
.Fl n
or
.Fl p .
In auto-split mode, Ruby executes
.Dl $F = $_.split
at beginning of each loop. at beginning of each loop.
.fi .Pp
.TP .It Fl c
.B -c Causes Ruby to check the syntax of the script and exit without
causes Ruby to check the syntax of the script and exit without executing. If there are no syntax errors, Ruby will print
executing. If there are no syntax errors, Ruby will print "Syntax .Dq Syntax OK
OK" to the standard output. to the standard output.
.TP .Pp
.B --copyright .It Fl d
prints the copyright notice. .It Fl -debug
.TP Turns on debug mode.
.B -d --debug .Li "$DEBUG"
turns on debug mode. $DEBUG will set true. will set true.
.TP .Pp
.B -e command .It Fl e Ar command
specifies script from command-line while telling Ruby to not Specifies script from command-line while telling Ruby to not search
search argv for script filenames. argv for script filenames.
.TP .Pp
.B -F pattern .It Fl h
specifies input field separator ($;). .It Fl -help
.TP Prints a summary of the options.
.B -h --help .Pp
prints a summary of the options. .It Fl i Ar extension
.TP Specifies in-place-edit mode. The extension, if specified, is added
.B -i extension to old filename to make a backup copy. For example:
specifies in-place-edit mode. The extension, if specified, is .Bd -literal -offset indent
added to old filename to make a backup copy. % echo matz > /tmp/junk
example: % cat /tmp/junk
.nf matz
.ne 8 % ruby -p -i.bak -e '$_.upcase!' /tmp/junk
\& % echo matz > /tmp/junk % cat /tmp/junk
\& % cat /tmp/junk MATZ
\& matz % cat /tmp/junk.bak
\& % ruby -p -i.bak -e '$_.upcase!' /tmp/junk matz
\& % cat /tmp/junk .Ed
\& MATZ .Pp
\& % cat /tmp/junk.bak .It Fl l
\& matz (The lowercase letter
.fi .Dq ell . )
.TP Enables automatic line-ending processing, which means to firstly set
.B -I directory .Li "$\e"
used to tell Ruby where to load the library scripts. Directory path to the value of
will be added to the load-path variable ($:'). .Li "$/" ,
.TP and secondly chops every line read using
.B -Kkcode .Li chop! .
specifies KANJI (Japanese) encoding. .Pp
.TP .It Fl n
.B -l Causes Ruby to assume the following loop around your script, which
enables automatic line-ending processing, which means to firstly set makes it iterate over filename arguments somewhat like
$\e to the value of $/, and secondly chops every line read using chop!. .Nm sed
.TP .Fl n
.B -n or
causes Ruby to assume the following loop around your script, .Nm awk .
which makes it iterate over filename arguments somewhat like .Bd -literal -offset indent
sed -n or awk. while gets
.nf ...
.ne 3 end
\& while gets .Ed
\& ... .Pp
\& end .It Fl p
.fi Acts mostly same as -n switch, but print the value of variable
.TP .Li "$_"
.B -p at the each end of the loop. For example:
acts mostly same as -n switch, but print the value of variable .Bd -literal -offset indent
$_ at the each end of the loop. % echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
example: MATZ
.nf .Ed
.ne 2 .Pp
\& % echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"' .It Fl r Ar library
\& MATZ Causes Ruby to load the library using require. It is useful when using
.fi .Fl n
.TP or
.B -r library .Fl p .
causes Ruby to load the library using require. It is useful .Pp
with switches -n or -p. .It Fl s
.TP Enables some switch parsing for switches after script name but before
.B -s any filename arguments (or before a
enables some switch parsing for switches after script name but before .Fl - ) .
any filename arguments (or before a --). Any switches found there are Any switches found there are removed from
removed from ARGV and set the corresponding variable in the script. .Li ARGV
example: and set the corresponding variable in the script. For example:
.nf .Bd -literal -offset indent
.ne 3 #! /usr/local/bin/ruby -s
\& #! /usr/local/bin/ruby -s # prints "true" if invoked with `-xyz' switch.
\& # prints "true" if invoked with `-xyz' switch. print "true\en" if $xyz
\& print "true\en" if $xyz .Ed
.fi .Pp
.TP On some systems
.B -S .Li "$0"
makes Ruby use the PATH environment variable to search for does not always contain the full pathname, so you need the
script, unless if its name begins with a slash. This is used to .Fl S
emulate #! on machines that don't support it, in the following switch to tell Ruby to search for the script if necessary. To handle
manner: embedded spaces or such. A better construct than
.nf .Li "$*"
.ne 2 would be
\& #! /usr/local/bin/ruby .Li ${1+"$@"} ,
\& # This line makes the next one a comment in ruby \e but it does not work if the script is being interpreted by
\& exec /usr/local/bin/ruby -S $0 $* .Xr csh 1 .
.fi .Pp
On some systems $0 does not always contain the full pathname, so you .It Fl v
need -S switch to tell Ruby to search for the script if necessary. To .It Fl -verbose
handle embedded spaces or such. A better construct than $* would be Enables verbose mode. Ruby will print its version at the beginning,
${1+"$@"}, but it does not work if the script is being interpreted by and set the variable
csh. .Li "$VERBOSE"
.TP to true. Some methods print extra messages if this variable is true.
.B -v --verbose If this switch is given, and no other switches are present, Ruby quits
enables verbose mode. Ruby will print its version at the beginning, after printing its version.
and set the variable `$VERBOSE' to true. Some methods print extra .Pp
messages if this variable is true. If this switch is given, and no .It Fl w
other switches are present, Ruby quits after printing its version. Enables verbose mode without printing version message at the
.TP beginning. It sets the
.B -T[level] .Li "$VERBOSE"
turns on taint checks at the specified level (default 1). variable to true.
.TP .Pp
.B --version .It Fl x Ns Op Ar directory
prints the version of Ruby interpreter. Tells Ruby that the script is embedded in a message. Leading garbage
.TP will be discarded until the first that starts with
.B -w .Dq #!
enables verbose mode without printing version message at the and contains the string,
beginning. It set the `$VERBOSE' variable to true. .Dq ruby .
.TP Any meaningful switches on that line will applied. The end of script
.B -x[directory] must be specified with either EOF, ^D (control-D), ^Z (control-Z), or
tells Ruby that the script is embedded in a message. Leading garbage reserved word
will be discarded until the first that starts with "#!" and contains .Li __END__ .
the string, "ruby". Any meaningful switches on that line will applied. If the directory name is specified, Ruby will switch to that directory
The end of script must be specified with either EOF, ^D (control-D), before executing script.
^Z (control-Z), or reserved word __END__.If the directory name is .Pp
specified, Ruby will switch to that directory before executing script. .It Fl y
.TP .It Fl -yydebug
.B -C directory Turns on compiler debug mode. Ruby will print a bunch of internal
causes Ruby to switch to the directory. state messages during compiling scripts. You don't have to specify
.TP
.B -y --yydebug
turns on compiler debug mode. Ruby will print a bunch of internal
state messages during compiling scripts. You don't have to specify
this switch, unless you are going to debug the Ruby interpreter. this switch, unless you are going to debug the Ruby interpreter.
.PP .El
.SH AUTHOR .Pp
Ruby is designed and implemented by Yukihiro Matsumoto <matz@netlab.jp>. .Sh AUTHORS
Ruby is designed and implemented by
.An Yukihiro Matsumoto Aq matz@netlab.jp .