1 .\"Ruby is copyrighted by Yukihiro Matsumoto <matz@netlab.jp>.
3 .Dt RUBY(1) "" "Ruby Programmers Reference Guide"
8 .Nd Interpreted object-oriented scripting language
14 .Op Fl 0 Ns Op Ar octal
20 .Op Fl T Ns Op Ar level
21 .Op Fl W Ns Op Ar level
23 .Op Fl i Ns Op Ar extension
25 .Op Fl x Ns Op Ar directory
26 .Op - Ns Bro Cm enable Ns | Ns Cm disable Brc Ns - Ns Ar FEATURE
32 Ruby is an interpreted scripting language for quick and easy
33 object-oriented programming. It has many features to process text
34 files and to do system management tasks (as in Perl). It is simple,
35 straight-forward, and extensible.
37 If you want a language for easy object-oriented programming, or you
38 don't like the Perl ugliness, or you do like the concept of LISP, but
39 don't like too much parentheses, Ruby may be the language of your
42 Ruby's features are as follows:
45 Ruby is an interpreted language, so you don't have to recompile
46 programs written in Ruby to execute them.
48 .It Sy "Variables have no type (dynamic typing)"
49 Variables in Ruby can contain data of any type. You don't have to
50 worry about variable typing. Consequently, it has a weaker compile
53 .It Sy "No declaration needed"
54 You can use variables in your Ruby programs without any declarations.
55 Variable names denote their scope, local, global, instance, etc.
57 .It Sy "Simple syntax"
58 Ruby has a simple syntax influenced slightly from Eiffel.
60 .It Sy "No user-level memory management"
61 Ruby has automatic memory management. Objects no longer referenced
62 from anywhere are automatically collected by the garbage collector
63 built into the interpreter.
65 .It Sy "Everything is an object"
66 Ruby is the purely object-oriented language, and was so since its
67 creation. Even such basic data as integers are seen as objects.
69 .It Sy "Class, inheritance, and methods"
70 Of course, as an object-oriented language, Ruby has such basic
71 features like classes, inheritance, and methods.
73 .It Sy "Singleton methods"
74 Ruby has the ability to define methods for certain objects. For
75 example, you can define a press-button action for certain widget by
76 defining a singleton method for the button. Or, you can make up your
77 own prototype based object system using singleton methods, if you want
80 .It Sy "Mix-in by modules"
81 Ruby intentionally does not have the multiple inheritance as it is a
82 source of confusion. Instead, Ruby has the ability to share
83 implementations across the inheritance tree. This is often called
87 Ruby has iterators for loop abstraction.
90 In Ruby, you can objectify the procedure.
92 .It Sy "Text processing and regular expression"
93 Ruby has a bunch of text processing features like in Perl.
96 With built-in bignums, you can for example calculate factorial(400).
98 .It Sy "Exception handling"
101 .It Sy "Direct access to the OS"
104 system calls, often used in system programming.
106 .It Sy "Dynamic loading"
109 systems, you can load object files into the Ruby interpreter
114 Ruby interpreter accepts following command-line options (switches).
115 They are quite similar to those of
117 .Bl -tag -width "1234567890123" -compact
120 Prints the copyright notice.
123 Prints the version of Ruby interpreter.
125 .It Fl 0 Ns Op Ar octal
128 Specifies the input record separator
130 as an octal number. If no digit is given, the null character is taken
131 as the separator. Other switches may follow the digits.
133 turns Ruby into paragraph mode.
135 makes Ruby read whole file at once as a single string since there is
136 no legal character with that value.
138 .It Fl C Ar directory
139 .It Fl X Ar directory
140 Causes Ruby to switch to the directory.
143 .It Fl -encoding Ar encname
144 Specifies the encoding for the program codes.
147 Specifies input field separator
150 .It Fl I Ar directory
151 Used to tell Ruby where to load the library scripts. Directory path
152 will be added to the load-path variable
156 Specifies KANJI (Japanese) encoding.
161 environment variable to search for script, unless if its name begins
162 with a slash. This is used to emulate
164 on machines that don't support it, in the following manner:
165 .Bd -literal -offset indent
166 #! /usr/local/bin/ruby
167 # This line makes the next one a comment in Ruby \e
168 exec /usr/local/bin/ruby -S $0 $*
171 .It Fl T Ns Op Ar level
172 Turns on taint checks at the specified level (default 1).
174 .It Fl W Ns Op Ar level
175 Turns on verbose mode at the specified level, without printing version
176 message at the beginning. The level can be;
177 .Bl -hang -offset indent
179 Verbose mode is "silence". It sets the
184 Verbose mode is "medium". It sets the
189 Verbose mode is "verbose". It sets the
199 Turns on auto-split mode when used with
203 In auto-split mode, Ruby executes
205 at beginning of each loop.
208 Causes Ruby to check the syntax of the script and exit without
209 executing. If there are no syntax errors, Ruby will print
211 to the standard output.
220 Specifies script from command-line while telling Ruby not to search
221 the rest of arguments for a script file name.
225 Prints a summary of the options.
227 .It Fl i Ar extension
228 Specifies in-place-edit mode. The extension, if specified, is added
229 to old file name to make a backup copy. For example:
230 .Bd -literal -offset indent
231 % echo matz > /tmp/junk
234 % ruby -p -i.bak -e '$_.upcase!' /tmp/junk
242 (The lowercase letter
244 Enables automatic line-ending processing, which means to firstly set
248 and secondly chops every line read using
252 Causes Ruby to assume the following loop around your script, which
253 makes it iterate over file name arguments somewhat like
258 .Bd -literal -offset indent
265 Acts mostly same as -n switch, but print the value of variable
267 at the each end of the loop. For example:
268 .Bd -literal -offset indent
269 % echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
274 Causes Ruby to load the library using require. It is useful when using
280 Enables some switch parsing for switches after script name but before
281 any file name arguments (or before a
283 Any switches found there are removed from
285 and set the corresponding variable in the script. For example:
286 .Bd -literal -offset indent
287 #! /usr/local/bin/ruby -s
288 # prints "true" if invoked with `-xyz' switch.
289 print "true\en" if $xyz
294 does not always contain the full pathname, so you need the
296 switch to tell Ruby to search for the script if necessary. To handle
297 embedded spaces or such. A better construct than
301 but it does not work if the script is being interpreted by
305 Enables verbose mode. Ruby will print its version at the beginning,
308 to true. Some methods print extra messages if this variable is true.
309 If this switch is given, and no other switches are present, Ruby quits
310 after printing its version.
313 Enables verbose mode without printing version message at the
314 beginning. It sets the
318 .It Fl x Ns Op Ar directory
319 Tells Ruby that the script is embedded in a message. Leading garbage
320 will be discarded until the first that starts with
322 and contains the string,
324 Any meaningful switches on that line will applied. The end of script
325 must be specified with either
327 .Li "^D" ( Li "control-D" ) ,
328 .Li "^Z" ( Li "control-Z" ) ,
331 If the directory name is specified, Ruby will switch to that directory
332 before executing script.
336 Turns on compiler debug mode. Ruby will print a bunch of internal
337 state messages during compiling scripts. You don't have to specify
338 this switch, unless you are going to debug the Ruby interpreter.
340 .It Fl -disable- Ns Ar FEATURE
341 .It Fl -enable- Ns Ar FEATURE
342 Disables (or enables) the specified
348 Disables (or enables) RubyGems libraries. By default, Ruby will load the latest
349 version of each installed gem. The
351 constant is true if RubyGems is enabled, false if otherwise.
353 .It Fl -disable-rubyopt
354 .It Fl -enable-rubyopt
355 Ignores (or considers) the
357 environment variable. By default, Ruby considers the variable.
361 Disables (or enables) all features.
364 Enables verbose mode without printing version message at the
365 beginning. It sets the
368 If this switch is given, and no other switches are present, Ruby quits
369 after printing its version.
373 .Bl -tag -width "RUBYLIB_PREFIX" -compact
375 A colon-separated list of directories that are added to Ruby's
377 .Pf ( Li "$:" ) . Directories from this environment variable are searched
378 before the standard load path is searched.
381 .Dl RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext"
384 Additional Ruby options.
390 A colon-separated list of directories that Ruby searches for
391 Ruby programs when the
393 flag is specified. This variable precedes the
395 environment variable.
398 The path to the system shell command. This environment variable is
399 enabled for only mswin32, mingw32, and OS/2 platforms. If this
400 variable is not defined, Ruby refers to
406 environment variable on calling Kernel#system.
408 .It Ev RUBYLIB_PREFIX
409 This variable is obsolete.
413 Ruby is designed and implemented by
414 .An Yukihiro Matsumoto Aq matz@netlab.jp .