RUBY(1)
π RUBY(1) β Ruby Programmer's Reference Guide π
okay bestie, sit DOWN, because we're about to talk about ruby and this is genuinely one of the most iconic things in the whole manual set π«Ά
β¨ NAME β¨
ruby β Interpreted object-oriented scripting language π
β¨ SYNOPSIS β¨
like, here's the whole vibe in one breath:
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 ...]
no cap, that's a LOT of flags, and yes, we're getting to every single one of them. not me gatekeeping a single option. π
β¨ DESCRIPTION β¨
so Ruby is an interpreted scripting language made for quick and easy object-oriented programming. she's got a whole arsenal of features for processing text files and doing system management tasks β think Perl energy, but make it cute π. She's simple, straightforward, and extensible. periodt.
if you're looking for a language that does easy object-oriented programming, or you simply cannot with the Perl ugliness π, or you're lowkey obsessed with the concept of LISP but the parentheses are giving you a headache β Ruby might just be your language of choice. the vibe check passes. π₯
β¨ FEATURES β¨
okay so here's the full rundown of what Ruby's features are, and bestie, she ate:
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, slay. β¨
Variables have no type (dynamic typing)
Variables in Ruby can contain data of any type. no stressing about variable typing, no crying over declarations. consequently β and this is the tradeoff, bestie, listen β it has a weaker compile time check. π
No declaration needed
You can use variables in your Ruby programs without any declarations at all. Variable names denote their scope β global, class, instance, or local. the name tells you everything, iykyk. π
Simple syntax
Ruby has a simple syntax influenced slightly from Eiffel. simple! clean! iconic! π
No user-level memory management
Ruby has automatic memory management. objects that are no longer referenced from anywhere get automatically collected by the garbage collector built into the interpreter. so you just... don't think about it. she handles it. π§
Everything is an object
Ruby is a purely object-oriented language, and has been so since its creation. even such basic data as integers are seen as objects. everything. is. an. object. main character energy from day one. π
Class, inheritance, and methods
Being an object-oriented language, Ruby naturally has basic features like classes, inheritance, and methods. the fundamentals, and she's got them fr fr.
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 β if you want to get ambitious β you can make up your own prototype based object system using singleton methods. go off. π₯
Mix-in by modules
Ruby intentionally does not have multiple inheritance, because it is a source of confusion. instead, Ruby has the ability to share implementations across the inheritance tree. this is often called a βMix-inβ. she said "no chaos, only sharing." π
Iterators
Ruby has iterators for loop abstraction. loops but cuter, basically. πΈ
Closures
In Ruby, you can objectify the procedure. β¨
Text processing and regular expressions
Ruby has a bunch of text processing features like in Perl. regex girlies, this one's for you π«Ά
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, without dependence on Unicode. multilingual and unbothered π
Bignums
with built-in bignums, you can for example calculate factorial(400). big numbers, no problem. π’
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. thus you can write your application in your own programming language on top of Ruby. this is genuinely unhinged and I'm obsessed ππ₯
Exception handling
As in Java(tm). π
Direct access to the OS
Ruby can use most Unix system calls, often used in system programming. she talks to the kernel directly, bestie. π
Dynamic loading
On most Unix systems, you can load object files into the Ruby interpreter on-the-fly. β¨
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 whole vibe so far bestie, and we're only just getting started β more parts incoming, don't go anywhere π
β¨ OPTIONS β¨
okay bestie, the Ruby interpreter accepts the following command-line options (switches), and they are quite similar to those of perl(1). like, same family energy, no cap. π
--copyrightβ Prints the copyright notice, and quits immediately without running any script. π--versionβ Prints the version of the Ruby interpreter, and quits immediately without running any script. β¨-0[octal]β (The digit βzeroβ.) Specifies the input record separator ($/) as an octal number. If no digit is given, the null character is taken as the separator. Other switches may follow the digits.-00turns Ruby into paragraph mode.-0777makes Ruby read whole file at once as a single string since there is no legal character with that value. π-C directory,-X directoryβ Causes Ruby to switch to the directory. π¦-E external[:internal],--encoding external[:internal]β Specifies the default value(s) for external encodings and internal encoding. Values should be separated with colon (:). You can omit the one for internal encodings, then the value (Encoding.default_internal) will benil. π--external-encoding=encoding,--internal-encoding=encodingβ Specify the default external or internal character encoding. πΈ-F patternβ Specifies input field separator ($;). π-I directoryβ Used to tell Ruby where to load the library scripts. Directory path will be added to the load-path variable ($:). π-K kcodeβ Specifies KANJI (Japanese) encoding. The default value for script encodings (__ENCODING__) and external encodings (Encoding.default_external) will be the specified one.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 script, unless its name begins with a slash. This is used to emulate#!on machines that don't support it, in the following manner:
#! /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 does not always contain the full pathname, so you need the -S switch to tell Ruby to search for the script if necessary (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). π€
-T[level=1]β Turns on taint checks at the specified level (default1). π«Ά-Uβ Sets the default value for internal encodings (Encoding.default_internal) toUTF-8. π-W[level=2]β Turns on verbose mode at the specified level without printing the version message at the beginning. The level can be:0β Verbose mode is "silence". It sets the$VERBOSEtonil.1β Verbose mode is "medium". It sets the$VERBOSEtofalse.2 (default)β Verbose mode is "verbose". It sets the$VERBOSEtotrue.-W2is the same as-w.
-aβ Turns on auto-split mode when used with-nor-p. In auto-split mode, Ruby executes
$F = $_.split
at beginning of each loop. π₯
-cβ Causes Ruby to check the syntax of the script and exit without executing. If there are no syntax errors, Ruby will print βSyntax OKβ to the standard output. β-d,--debugβ Turns on debug mode.$DEBUGwill be set totrue. π-e commandβ Specifies script from 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. π-i extensionβ Specifies in-place-edit mode. The extension, if specified, is added to 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
-lβ (The lowercase letter βellβ.) Enables automatic line-ending processing, which means to firstly set$\to the value of$/, and secondly chops every line read usingchomp!. βοΈ-nβ Causes Ruby to assume the following loop around your script, which makes it iterate over file name arguments somewhat likesed -norawk.
while gets
...
end
-pβ Acts mostly same as-nswitch, but print the value of variable$_at the each end of the loop. For example:
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
MATZ
-r libraryβ Causes Ruby to load the library usingrequire. It is useful when using-nor-p. π¦-sβ Enables some switch parsing for switches after script name but before any file name arguments (or before a--). Any switches found there are 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 istrue. If this switch is given, and no other switches are present, Ruby quits after printing its version. π£-wβ Enables verbose mode without printing version message at the beginning. It sets the$VERBOSEvariable totrue. β οΈ-x[directory]β Tells Ruby that the script is embedded in a message. Leading garbage will be discarded until the first line that starts with β#!β and contains the string, βrubyβ. Any meaningful switches on that line will be applied. The end of the script must be specified with eitherEOF,^D(control-D),^Z(control-Z), or the reserved word__END__. If the directory name is specified, Ruby will switch to that directory before executing script. π§-y,--yydebugβ DO NOT USE. Turns on compiler debug mode. Ruby will print a bunch of internal state messages during compilation. Only specify this switch you are going to debug the Ruby interpreter. π--disable-FEATURE,--enable-FEATUREβ Disables (or enables) the specified FEATURE.--disable-gems,--enable-gemsβ Disables (or enables) RubyGems libraries. By default, Ruby will load the latest version of each installed gem. TheGemconstant istrueif RubyGems is enabled,falseif otherwise. π--disable-rubyopt,--enable-rubyoptβ Ignores (or considers) theRUBYOPTenvironment variable. By default, Ruby considers the variable. πΏ--disable-all,--enable-allβ Disables (or enables) all features. π¨
--dump=targetβ Dump some information. Prints the specified target.targetcan be one of:versionβ Print version description (same as--version).usageβ Print a brief usage message (same as-h).helpβ Show long help message (same as--help).syntaxβ Check syntax (same as-c --yydebug).
Or one of the following, which are intended for debugging the interpreter:
yydebugβ Enable compiler debug mode (same as--yydebug).parsetreeβ Print a textual representation of the Ruby AST for the program.parsetree_with_commentβ Print a textual representation of the Ruby AST for the program, but with each node annoted with the associated Ruby source code.insnsβ Print a list of disassembled bytecode instructions.insns_without_optβ Print the list of disassembled bytecode instructions before various optimizations have been applied.
--verboseβ Enables verbose mode without printing version message at the beginning. It sets the$VERBOSEvariable totrue. If this switch is given, and no script arguments (script file or-eoptions) are present, Ruby quits immediately. π
πΈ ENVIRONMENT πΈ
Okay bestie, listen up, because these env vars are the ones you set in your shell profile and then forget about for a year π
RUBYLIBβ a colon-separated list of directories that get added to Ruby's library load path ($:). The dirs from this variable get searched before the standard load path is even looked at. like:
RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext"
RUBYOPTβ extra Ruby options, bestie. like:
RUBYOPT="-w -Ke"
Heads up fr fr:RUBYOPTcan contain only-d,-E,-I,-K,-r,-T,-U,-v,-w,-W,--debug,--disable-FEATUREand--enable-FEATURE. That's the whole guest list, no plus-ones. π
RUBYPATHβ a colon-separated list of directories Ruby searches for Ruby programs when the-Sflag is specified. This variable comes before thePATHenvironment variable. main character energy β¨RUBYSHELLβ the path to the system shell command. This one is enabled for only mswin32, mingw32, and OS/2 platforms. If it's not defined, Ruby refers toCOMSPEC. very niche, very specific, we respect it πPATHβ Ruby refers to thePATHenvironment variable when callingKernel#system.
And Ruby depends on some RubyGems-related environment variables too, unless RubyGems is disabled. See the help of gem(1) like this:
% gem help
ποΈ GC ENVIRONMENT ποΈ
Not the garbage collection you're thinking of, bestie, this is the real one π
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" means the Ruby object heap of fixed-sized slots, while "malloc" means auxiliary allocations β commonly called the "process heap". So there are at least two possible ways to trigger a GC:
- Reaching the object limit.
- Reaching the malloc limit.
In Ruby 2.1 the generational GC showed up (iconic), and the limits got split into young and old generations, which gives you two more 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 these 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 many slots after GC. Allocate this number of slots if there aren't enough slots. Introduced in Ruby 2.1, default:4096.RUBY_GC_HEAP_GROWTH_FACTORβ increase the 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, which prevents 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 than R * 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.0.RUBY_GC_MALLOC_LIMITβ the initial limit of young generation allocation from the malloc-family. GC will start when this limit is reached. Default:16MB.RUBY_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:16MB.RUBY_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:128MB.RUBY_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 π§΅
Okay so these ones are implementation-dependent and subject to change with different versions of Ruby β so don't @ me if they shift, bestie π«Ά
The VM stack is used for pure-Ruby code and is managed by the virtual machine. The machine stack is used by the operating system, and its usage depends on C extensions as well as C compiler options.
Using lower values for these may let applications keep more Fibers or Threads running β but it increases the chance of SystemStackError exceptions and segmentation faults (SIGSEGV). π So like, tread carefully, that's not a fun vibe.
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) or1048575(64-bit)RUBY_THREAD_MACHINE_STACK_SIZEβ machine stack size used at thread creation. default:524288or1048575RUBY_FIBER_VM_STACK_SIZEβ VM stack size used at fiber creation. default:65536or131072RUBY_FIBER_MACHINE_STACK_SIZEβ machine stack size used at fiber creation. default:262144or524288
π SEE ALSO π
https://www.ruby-lang.org/β the official web site. the mothership πhttps://www.ruby-toolbox.com/β comprehensive catalog of Ruby libraries. your shopping mall ποΈ
π 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. Like. Immediately immediately. That's the whole point of the warning, bestie. π
π AUTHORS π
Ruby is designed and implemented by Yukihiro Matsumoto <matz@netlab.jp>. a literal legend, we stan π
See β¨https://bugs.ruby-lang.org/projects/ruby/wiki/Contributorsβ© for contributors to Ruby.
and that's a wrap on the whole page, bestie π This is from the UNIX manual, dated April 14, 2018, for RUBY(1). Go write something cute and chaotic, and remember: the GC is always watching π β¨
π¦ where this page comes from
- ubuntu noble: ruby3.2 3.2.3-1build3 Β· BSD-2-Clause OR Ruby
- ubuntu noble: ruby3.2 3.2.3-1ubuntu0.24.04.8 Β· 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