RUBY(1)
π RUBY β like, the whole vibe check
okay bestie, welcome to the RUBY(1) page β Ruby Programmer's Reference Guide, the one and only, the blueprint, the origin story π
β¨ NAME β¨
ruby β an interpreted, object-oriented scripting language π
(yes that's the whole name section, she's lowkey humble like that)
πΈ SYNOPSIS πΈ
ruby [--copyright] [--version] [-SUacdlnpswvy] [-0[octal]]
[-C directory] [-E external[:internal]] [-F[pattern]]
[-I directory] [-K[c]] [-T[level]] [-W[level]] [-e command]
[-i[extension]] [-r library] [-x[directory]]
[--{enable|disable}-FEATURE] [--dump=target] [--verbose] [--]
[program_file] [argument ...]
look at all those flags. she contains multitudes. don't worry, we're gonna go through literally every single one, no skipping, I promise π«Ά
π¦ DESCRIPTION π¦
Ruby is an interpreted scripting language built for quick and easy object-oriented programming. She's got so many features for processing text files and doing system management tasks (like in Perl, bestie, if you know you know). She's simple, she's straightforward, and she's extensible. Periodt.
So here's the vibe check: if you want a language for easy object-oriented programming, OR you're not into that Perl ugliness, OR you actually love the concept of LISP but cannot deal with that many parentheses? Ruby might be your language of choice. No cap. π
π₯ FEATURES π₯
Ruby's features, bestie, are as follows:
π« Interpretive
Ruby is an interpreted language, so you literally don't have to recompile programs written in Ruby to execute them. Write it, run it, done. Main character energy. β¨
π« Variables have no type (dynamic typing)
Variables in Ruby can hold data of any type. You don't have to worry about variable typing, which is so freeing. Consequently though β and this is the tradeoff, bestie β it has a weaker compile time check. π
π« No declaration needed
You can use variables in your Ruby programs without any declarations whatsoever. The variable names themselves denote their scope β global, class, instance, or local. It's giving effortless. π
π« Simple syntax
Ruby has a simple syntax, influenced slightly from Eiffel. (Eiffel! She's got taste. π)
π« No user-level memory management
Ruby has automatic memory management, and honestly? Slay. Objects that are no longer referenced from anywhere get automatically collected by the garbage collector built right into the interpreter. You never think about it, she handles it. π§
π« Everything is an object
Ruby is a purely object-oriented language, and she has been since her creation. Even basic data like integers are seen as objects. Everything. The way she doesn't make exceptions for anybody?? Iconic. β
π« Class, inheritance, and methods
Being an object-oriented language, Ruby naturally has the basic features β classes, inheritance, and methods. The fundamentals, and she ate. π
π« Singleton methods
Ruby has the ability to define methods for certain objects. For example, you can define a press-button action for a certain widget by defining a singleton method for the button. Or β and this is the fun part β you can make up your own prototype based object system using singleton methods, if you want to. Go off, honestly. π
π« Mix-in by modules
Ruby intentionally does not have multiple inheritance, because that's a source of confusion and she's above the drama. Instead, Ruby can share implementations across the inheritance tree. This is often called a βMix-inβ. π
π« Iterators
Ruby has iterators for loop abstraction. Clean. β¨
π« Closures
In Ruby, you can objectify the procedure. Yes bestie, the procedure. An object now. π
π« Text processing and regular expressions
Ruby has a whole bunch of text processing features, like in Perl. π
π« M17N, character set independent
Ruby supports multilingualized programming. Easy to process texts written in many different natural languages and encoded in many different character encodings β and all of that without dependence on Unicode. She's worldly. She contains multitudes. π¦
π« Bignums
With built-in bignums, you can for example calculate factorial(400). Like. Bestie. factorial(400). ππ₯
π« Reflection and domain specific languages
Class is also an instance of the Class class. Definition of classes and methods is an expression just as 1+1 is. So your programs can even write and modify programs. Which means you can write your application in your own programming language on top of Ruby. The power?? Unreal. π
π« Exception handling
As in Java(tm). That's it, that's the bullet. π
π« Direct access to the OS
Ruby can use most Unix system calls, which are often used in system programming. She speaks OS. Fluently. π₯οΈβ¨
π« Dynamic loading
On most Unix systems, you can load object files into the Ruby interpreter on-the-fly. No restart, no ceremony. π«
π« Rich libraries
In addition to the βbuiltin librariesβ and βstandard librariesβ that are bundled with Ruby, a vast amount of third-party libraries (βgemsβ) are available via the package management system called βRubyGemsβ β namely the gem(1) command. Visit RubyGems.org (https://rubygems.org/) to find the gems you need, and explore GitHub (https://github.com/) to see how they are being developed and used. ππ
okay that's the features section done, and there's so much more coming β don't go anywhere bestie, we're just getting started π«Ά
β¨ OPTIONS β¨
okay bestie, so the Ruby interpreter takes all these command-line options (switches) and ngl they're very similar to the ones perl(1) has. iconic family resemblance fr fr π
--copyrightβ prints the copyright notice and dips immediately, no script runs at all. like it said what it said and left πΈ--versionβ prints the version of the Ruby interpreter and bounces right away, again without running any script. short and sweet periodt β¨-0[octal]β (that's the digit "zero", bestie, not the letter) sets the input record separator ($/) to an octal number. If you don't give it a digit, the null character becomes the separator. Other switches can follow the digits.-00turns Ruby into paragraph mode. And-0777makes Ruby read the whole file at once as a single string, because there is literally no legal character with that value π-C directory,-X directoryβ makes Ruby switch to that directory. simple as π¦-E external[:internal],--encoding external[:internal]β sets the default value(s) for external encodings and internal encoding. The values get separated with a colon (:).
You can totally omit the internal one, and then that value (Encoding.default_internal) will be nil. no drama π
--external-encoding=encoding,--internal-encoding=encodingβ specify the default external or internal character encoding. pick your fighter π-F patternβ sets the input field separator ($;). π«-I directoryβ tells Ruby where to load the library scripts from. The directory path gets added to the load-path variable ($:). π-K kcodeβ sets the KANJI (Japanese) encoding. The default for script encodings (__ENCODING__) and external encodings (Encoding.default_external) becomes the one you picked.kcodecan be one of:eβ EUC-JPsβ Windows-31J (CP932)uβ UTF-8nβ ASCII-8BIT (BINARY)
-Sβ makes Ruby use thePATHenvironment variable to search for the script, unless its name starts with a slash. This is how you emulate#!on machines that don't support it, like this:
#! /usr/local/bin/ruby
# This line makes the next one a comment in Ruby \
exec /usr/local/bin/ruby -S $0 $*
On some systems $0 doesn't always have the full pathname, so you need the -S switch to tell Ruby to go hunt for the script if needed (to handle embedded spaces and such). A better construct than $* would be ${1+"$@"}, but it does not work if the script is being interpreted by csh(1). rip π
-T[level=1]β turns on taint checks at the level you specify (default is1). π₯-Uβ sets the default value for internal encodings (Encoding.default_internal) to UTF-8. slay β¨-W[level=2]β turns on verbose mode at the level you specify, without printing the version message at the beginning. The level can be:0β verbose mode is "silence". It sets$VERBOSEtonil.1β verbose mode is "medium". It sets$VERBOSEtofalse.2(default) β verbose mode is "verbose". It sets$VERBOSEtotrue.-W2is the same as-w.
-aβ turns on auto-split mode when you use it with-nor-p. In auto-split mode, Ruby runs
$F = $_.split
at the beginning of each loop. πΈ
-cβ makes Ruby check the syntax of the script and exit without executing it. If there are no syntax errors, Ruby prints "Syntax OK" to standard output. no cap, that's a whole vibe check for your code π-d,--debugβ turns on debug mode.$DEBUGgets set totrue. π-e commandβ specifies the script from the command line, while telling Ruby not to search the rest of the arguments for a script file name. π¦-h,--helpβ prints a summary of the options. your lil cheat sheet bestie π-i extensionβ specifies in-place-edit mode. The extension, if you give one, gets added to the old file name to make a backup copy. For example:
% echo matz > /tmp/junk
% cat /tmp/junk
matz
% ruby -p -i.bak -e '$_.upcase!' /tmp/junk
% cat /tmp/junk
MATZ
% cat /tmp/junk.bak
matz
backup bestie behavior, we love to see it π
-lβ (the lowercase letter "ell", don't get it twisted) enables automatic line-ending processing, which means it first sets$\to the value of$/, and then chops every line read usingchomp!. π-nβ makes Ruby assume the following loop around your script, which makes it iterate over the file name arguments kinda likesed -norawk:
while gets
...
end
-pβ acts mostly the same as the-nswitch, but prints the value of the variable$_at each end of the loop. For example:
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
MATZ
periodt π
-r libraryβ makes Ruby load the library usingrequire. super useful when you're using-nor-p. π«Ά-sβ enables some switch parsing for switches that come after the script name but before any file name arguments (or before a--). Any switches found there get removed fromARGVand set the corresponding variable in the script. For example:
#! /usr/local/bin/ruby -s
# prints "true" if invoked with `-xyz' switch.
print "true\n" if $xyz
-vβ enables verbose mode. Ruby will print its version at the beginning and set the variable$VERBOSEtotrue. Some methods print extra messages if this variable is true. And if you give this switch and no other switches are present, Ruby quits after printing its version. it just wanted you to know β¨-wβ enables verbose mode without printing the version message at the beginning. It sets the$VERBOSEvariable totrue. π₯-x[directory]β tells Ruby that the script is embedded in a message. Leading garbage gets discarded until the first line that starts with "#!" and contains the string "ruby". Any meaningful switches on that line get applied. The end of the script has to be marked with eitherEOF,^D(control-D),^Z(control-Z), or the reserved word__END__. And if you specify the directory name, Ruby switches to that directory before executing the script. π§-y,--yydebugβ DO NOT USE.
bestie I am so serious, do not touch this one π
It turns on compiler debug mode. Ruby will print a whole bunch of internal state messages during compilation. Only specify this switch if you are literally going to debug the Ruby interpreter itself. π
--disable-FEATURE,--enable-FEATUREβ disables (or enables) the specifiedFEATURE.--disable-gems,--enable-gemsβ disables (or enables) RubyGems libraries. By default, Ruby loads the latest version of each installed gem. TheGemconstant istrueif RubyGems is enabled,falseotherwise. π--disable-rubyopt,--enable-rubyoptβ ignores (or considers) theRUBYOPTenvironment variable. By default, Ruby considers the variable. π--disable-all,--enable-allβ disables (or enables) all features. all of them. the whole menu. π
--dump=targetβ dump some information.
Prints the specified target. target can be one of:
versionβ version description, same as--versionusageβ brief usage message, same as-hhelpβ show long help message, same as--helpsyntaxβ check of syntax, same as-c --yydebugyydebugβ compiler debug mode, same as--yydebug
Only specify this switch if you are going to debug the Ruby interpreter.
parsetreeparsetree_with_commentβ AST nodes tree
Only specify this switch if you are going to debug the Ruby interpreter.
insnsβ disassembled instructions
Only specify this switch if you are going to debug the Ruby interpreter.
--verboseβ enables verbose mode without printing the version message at the beginning. It sets the$VERBOSEvariable totrue. And if you give this switch and no script arguments (script file or-eoptions) are present, Ruby quits immediately. bye bestie π
πΏ ENVIRONMENT πΏ
RUBYLIBβ a colon-separated list of directories that get added to Ruby's library load path ($:). Directories from this environment variable are searched before the standard load path is searched. β¨
e.g.:
RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext"
RUBYOPTβ additional Ruby options. π
e.g.
RUBYOPT="-w -Ke"
Note that RUBYOPT can contain only -d, -E, -I, -K, -r, -T, -U, -v, -w, -W, --debug, --disable-FEATURE and --enable-FEATURE. that's the whole guest list, don't try to sneak anyone else in π
RUBYPATHβ a colon-separated list of directories that Ruby searches for Ruby programs when the-Sflag is specified. This variable comes before thePATHenvironment variable. π¦RUBYSHELLβ the path to the system shell command. This environment variable is enabled for onlymswin32,mingw32, and OS/2 platforms. If this variable isn't defined, Ruby refers toCOMSPEC. πPATHβ Ruby refers to thePATHenvironment variable when callingKernel#system. β
And Ruby depends on some RubyGems related environment variables unless RubyGems is disabled. See the help of gem(1) as below. π₯
% gem help
β¨ GC ENVIRONMENT β¨
Okay so bestie, the Ruby garbage collector (GC) tracks objects in fixed-sized slots, but each object may have auxiliary memory allocations handled by the malloc family of C standard library calls (malloc(3), calloc(3), and realloc(3)). In this documentation, the "heap" refers to the Ruby object heap of fixed-sized slots, while "malloc" refers to auxiliary allocations commonly referred to as the "process heap". Thus there are at least two possible ways to trigger GC:
- Reaching the object limit.
- Reaching the malloc limit.
In Ruby 2.1, the generational GC was introduced and the limits are divided into young and old generations, providing two additional ways to trigger a GC:
- Reaching the old object limit.
- Reaching the old malloc limit.
There are currently 4 possible areas where the GC may be tuned by the following 11 environment variables:
RUBY_GC_HEAP_INIT_SLOTSβ Initial allocation slots. Introduced in Ruby 2.1, default: 10000.RUBY_GC_HEAP_FREE_SLOTSβ Prepare at least this amount of slots after GC. Allocate this number slots if there are not enough slots. Introduced in Ruby 2.1, default: 4096RUBY_GC_HEAP_GROWTH_FACTORβ Increase allocation rate of heap slots by this factor. Introduced in Ruby 2.1, default: 1.8, minimum: 1.0 (no growth)RUBY_GC_HEAP_GROWTH_MAX_SLOTSβ Allocation rate is limited to this number of slots, preventing excessive allocation due toRUBY_GC_HEAP_GROWTH_FACTOR. Introduced in Ruby 2.1, default: 0 (no limit)RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTORβ Perform a full GC when the number of old objects is more thanR * N, where R is this factor and N is the number of old objects after the last full GC. Introduced in Ruby 2.1.1, default: 2.0RUBY_GC_MALLOC_LIMITβ The initial limit of young generation allocation from the malloc-family. GC will start when this limit is reached. Default: 16MBRUBY_GC_MALLOC_LIMIT_MAXβ The maximum limit of young generation allocation from malloc before GC starts. Prevents excessive malloc growth due toRUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR. Introduced in Ruby 2.1, default: 32MB.RUBY_GC_MALLOC_LIMIT_GROWTH_FACTORβ Increases the limit of young generation malloc calls, reducing GC frequency but increasing malloc growth untilRUBY_GC_MALLOC_LIMIT_MAXis reached. Introduced in Ruby 2.1, default: 1.4, minimum: 1.0 (no growth)RUBY_GC_OLDMALLOC_LIMITβ The initial limit of old generation allocation from malloc, a full GC will start when this limit is reached. Introduced in Ruby 2.1, default: 16MBRUBY_GC_OLDMALLOC_LIMIT_MAXβ The maximum limit of old generation allocation from malloc before a full GC starts. Prevents excessive malloc growth due toRUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR. Introduced in Ruby 2.1, default: 128MBRUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTORβ Increases the limit of old generation malloc allocation, reducing full GC frequency but increasing malloc growth untilRUBY_GC_OLDMALLOC_LIMIT_MAXis reached. Introduced in Ruby 2.1, default: 1.2, minimum: 1.0 (no growth)
π§΅ STACK SIZE ENVIRONMENT π§΅
Stack size environment variables are implementation-dependent and subject to change with different versions of Ruby. The VM stack is used for pure-Ruby code and managed by the virtual machine. Machine stack is used by the operating system and its usage is dependent on C extensions as well as C compiler options. Using lower values for these may allow applications to keep more Fibers or Threads running; but increases the chance of SystemStackError exceptions and segmentation faults (SIGSEGV). Be careful, bestie β that's giving risky. These environment variables are available since Ruby 2.0.0. All values are specified in bytes.
RUBY_THREAD_VM_STACK_SIZEβ VM stack size used at thread creation. default: 524288 (32-bit CPU) or 1048575 (64-bit)RUBY_THREAD_MACHINE_STACK_SIZEβ Machine stack size used at thread creation. default: 524288 or 1048575RUBY_FIBER_VM_STACK_SIZEβ VM stack size used at fiber creation. default: 65536 or 131072RUBY_FIBER_MACHINE_STACK_SIZEβ Machine stack size used at fiber creation. default: 262144 or 524288
π SEE ALSO π
https://www.ruby-lang.org/β The official web site.https://www.ruby-toolbox.com/β Comprehensive catalog of Ruby libraries.
π REPORTING BUGS π
- Security vulnerabilities should be reported via an email to
security@ruby-lang.org. Reported problems will be published after being fixed. - Other bugs and feature requests can be reported via the Ruby Issue Tracking System (
https://bugs.ruby-lang.org/). Do not report security vulnerabilities via this system because it publishes the vulnerabilities immediately.
π AUTHORS π
- Ruby is designed and implemented by Yukihiro Matsumoto
<matz@netlab.jp>. - See β¨
https://bugs.ruby-lang.org/projects/ruby/wiki/Contributorsβ© for contributors to Ruby.
π That's the Ruby(1) manual wrapped, bestie! Source: UNIX manual, date: April 14, 2018, version: RUBY(1). Slay. β¨
π¦ where this page comes from
- debian bookworm: ruby3.1 3.1.2-7+deb12u1 Β· BSD-2-Clause OR Ruby
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms