RUBY(1)
๐ RUBY(1) โ Ruby Programmer's Reference Guide ๐
okay bestie, this is the manual page for ruby, and it's giving iconic scripting language energy. โจ
๐ท๏ธ NAME ๐ท๏ธ
ruby โ an interpreted, object-oriented scripting language. periodt. ๐
๐ 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]
[--crash-report=template] [--] [program_file] [argument ...]
๐ DESCRIPTION ๐
Ruby is an interpreted scripting language for quick and easy object-oriented programming. It has a bunch of features for processing text files and doing system management tasks (like Perl does). It's simple, straightforward, and extensible. No cap.
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 too many parentheses, Ruby might be your language of choice. ๐ซถ
โจ FEATURES โจ
Ruby's features are as follows, bestie:
- Interpretive โ Ruby is an interpreted language, so you don't have to recompile programs written in Ruby to execute them. literally just run it. ๐ฅ
- Variables have no type (dynamic typing) โ Variables in Ruby can hold data of any type. You don't have to worry about variable typing. Consequently, it has a weaker compile time check. slay.
- No declaration needed โ You can use variables in your Ruby programs without any declarations. Variable names denote their scope โ global, class, instance, or local. no pre-declare era. โจ
- Simple syntax โ Ruby has a simple syntax influenced slightly from Eiffel. cute.
- No user-level memory management โ Ruby has automatic memory management. Objects no longer referenced from anywhere are automatically collected by the garbage collector built into the interpreter. the GC is doing the most. ๐
- Everything is an object โ Ruby is a purely object-oriented language, and was so since its creation. Even such basic data as integers are seen as objects. yes, even your lil numbers. ๐
- Class, inheritance, and methods โ Being an object-oriented language, Ruby naturally has basic features like classes, inheritance, and methods. standard OOP behavior.
- Singleton methods โ Ruby has the ability to define methods for certain objects. For 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 own prototype based object system using singleton methods, if you want to. main character methods for one-off objects. ๐
- Mix-in by modules โ Ruby intentionally does not have the multiple inheritance as 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โ. ๐
- Iterators โ Ruby has iterators for loop abstraction. loops but make it abstract. ๐
- Closures โ In Ruby, you can objectify the procedure. yes bestie, procedures as objects.
- Text processing and regular expressions โ Ruby has a bunch of text processing features like in Perl. regex girlies rise. ๐
- 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. global vibes only. ๐
- Bignums โ With built-in bignums, you can for example calculate
factorial(400). math girlies, we ate. ๐ข - 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+1is. So your programs can even write and modify programs. Thus, you can write your application in your own programming language on top of Ruby. meta? iconic. ๐ช - Exception handling โ As in Java(tm). errors get caught, periodt.
- Direct access to the OS โ Ruby can use most Unix system calls, often used in system programming. lowkey sysadmin energy. ๐ฅ๏ธ
- Dynamic loading โ On most Unix systems, you can load object files into the Ruby interpreter on-the-fly. hot reload but for object files. ๐ซ
- 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. gems on gems on gems. ๐
โจ OPTIONS โจ
okay bestie, here's where it gets juicy ๐
the Ruby interpreter takes all of these command-line options (switches), and they're quite similar to the ones in perl(1). iykyk.
--copyrightโ prints the copyright notice and dips immediately, no script gets run. she's just here to flex the paperwork ๐--versionโ prints the version of the Ruby interpreter and also dips immediately without running any script.-0[octal]โ ok so this is the digit "zero", not the letter. ๐ธ it 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 (so iconic). and-0777makes Ruby read the whole file at once as a single string, since there's literally no legal character with that value. no cap.-C directory-X directoryโ makes Ruby switch to that directory. like, cd but make it Ruby ๐ถโโ๏ธ-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 the value (Encoding.default_internal) will be nil. slay.
--external-encoding=encoding--internal-encoding=encodingโ specify the default external or internal character encoding. two separate switches, both valid, both cute โจ-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 ($:). lowkey essential.-K kcodeโ specifies KANJI (Japanese) encoding ๐ฏ๐ต the default value for script encodings (__ENCODING__) and external encodings (Encoding.default_external) will be whatever you specify.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 the name begins with a slash. this is used to 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 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 doesn't work if the script is being interpreted by csh(1). ๐ญ the struggle is real.
-T[level=1]โ turns on taint checks at the specified level (default1). ๐ก๏ธ-Uโ sets the default value for internal encodings (Encoding.default_internal) to UTF-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$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 used with-nor-p. in auto-split mode, Ruby executes this:
$F = $_.split
at the beginning of each loop. ๐
--backtrace-limit=numโ limits the maximum length of backtraces tonumlines (default-1, meaning no limit). she said no more infinite scrolling ๐-cโ makes Ruby check the syntax of the script and exit without executing it. if there are no syntax errors, Ruby will print "Syntax OK" to the standard output. โจ vibe check, passed.-d--debugโ turns on debug mode.$DEBUGand$VERBOSEwill both be 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. very main character energy.-h--helpโ prints a summary of the options.-i extensionโ specifies in-place-edit mode. the extension, if specified, is 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
look at her go. ate that. ๐
-lโ (that's the lowercase letter "ell" bestie, don't get it twisted). enables automatic line-ending processing, which means: firstly set$\to the value of$/, and secondly chop 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 it prints the value of the variable$_at the each end of the loop. for example:
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
MATZ
literally iconic.
-r libraryโ makes Ruby load the library usingrequire. it's super useful when you're using-nor-p. ๐ซถ-sโ enables some switch parsing for switches after the script name but before any file name arguments (or before a--). any switches found there are removed fromARGVand set as 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. and if this switch is given and no other switches are present, Ruby quits after printing its version. she's shy like that ๐ฆ-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 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 the script. ๐ง-y--yydebugโ โ ๏ธ heads up bestie: this option is not guaranteed to be compatible.
turns on compiler debug mode. Ruby will print a bunch of internal state messages during compilation. only specify this switch if you're going to debug the Ruby interpreter. like, fr fr, this one's for the nerds (affectionate) ๐
--disable-FEATURE--enable-FEATUREโ disables (or enables) the specifiedFEATURE.--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. all or nothing, periodt. ๐
--dump=targetโ dumps some information. prints the specifiedtarget.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.insnsโ print a list of disassembled bytecode instructions.-optimizeโ disable various optimizations to print a list disassembled bytecode instructions.+error-tolerantโ enable error-tolerant parsing, whenyydebugorparsetree.+commentโ annotate a textual representation of the Ruby AST for the program with the associated Ruby source code.
๐ the more you know.
--verboseโ enables verbose mode without printing the version message at the beginning. it sets the$VERBOSEvariable totrue. and if this switch is given and no script arguments (script file or-eoptions) are present, Ruby quits immediately. bye bestie ๐--crash-report=templateโ sets the template of the path name to save the crash report. see theRUBY_CRASH_REPORTenvironment variable for details. ๐ญ (hopefully you never need her)
๐ฟ ENVIRONMENT ๐ฟ
okay bestie, this is where Ruby reads your vibe from the shell instead of from flags ๐ These are the environment variables it peeks at:
RUBYLIBโ a colon-separated list of directories that get added to Ruby's library load path ($:). Lowkey important detail: directories from this environment variable are searched before the standard load path is searched. So yeah, your stuff wins โจ
e.g.:
RUBYLIB="$HOME/lib/ruby:$HOME/lib/rubyext"
RUBYOPTโ extra Ruby options, injected straight in.
e.g.
RUBYOPT="-w -Ke"
Heads up bestie,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 that Ruby searches for Ruby programs when the-Sflag is specified. And it precedes thePATHenvironment variable, so it's giving main character energy, not backup dancer ๐ซถRUBYSHELLโ the path to the system shell command. Real talk: this environment variable is enabled for onlymswin32,mingw32, andOS/2platforms. If this variable is not defined, Ruby refers toCOMSPEC.RUBY_FREE_AT_EXITโ if set, Ruby tries to free all dynamically allocated memories. Introduced in Ruby 3.3, default: unset.RUBY_BOXโ if set to1, Ruby Box is enabled and users will be able to executeRuby::Box.new. Ruby Box is an experimental feature introduced in Ruby 4.0 ๐ฅ (experimental = tread carefully, she's new here)RUBY_IO_BUFFER_DEFAULT_SIZEโ the custom default buffer size ofIO::Buffer.RUBY_MAX_CPUโ the maximum number of native threads used by M:N Threads scheduler. Introduced in Ruby 3.3, default:8.RUBY_MN_THREADSโ if set to1, M:N Thread scheduler is enabled on the main Ractor. Introduced in Ruby 3.3, default: unset.RUBY_PAGERโ the pager command that will be used for--helpoption. Introduced in Ruby 3.0, default:PAGERenvironment variable.RUBY_THREAD_TIMESLICEโ sets the default thread time slice (thread quantum) in milliseconds. Introduced in Ruby 3.4, default:100ms.PATHโ Ruby refers to thePATHenvironment variable on 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 โจ
not me about to explain the garbage collector, but honestly it's so interesting, stay with me ๐ง
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". So 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 environment variables ๐
RUBY_GC_HEAP_n_INIT_SLOTSโ initial allocation of slots in a specific heap. The available heaps can be found in the keys ofGC.stat_heap.nis a decimal number between0and4. Introduced in Ruby 3.3.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:4096.RUBY_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 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_HEAP_REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIOโ used to calculate theremembered_wb_unprotected_objects_limitusing a ratio ofold_objects. Introduced in Ruby 3.3, default:0.1, minimum:0.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_HEAP_FREE_SLOTS_MIN_RATIOโ allocate additional pages when the number of free slots is lower than the value (total_slots * (this ratio)). Introduced in Ruby 2.4, default:0.2, minimum:0.0, maximum:1.0.RUBY_GC_HEAP_FREE_SLOTS_MAX_RATIOโ allow to free pages when the number of free slots is greater than the value (total_slots * (this ratio)). Introduced in Ruby 2.4, default:0.4, minimum:RUBY_GC_HEAP_FREE_SLOTS_MIN_RATIO, maximum:1.0.RUBY_GC_HEAP_FREE_SLOTS_GOAL_RATIOโ allocate slots to satisfy this formula:free_slots = total_slots * goal_ratio. In other words, prepare (total_slots * goal_ratio) free slots. if this value is0.0, then useRUBY_GC_HEAP_GROWTH_FACTORdirectly. Introduced in Ruby 2.4, default:0.65, minimum:RUBY_GC_HEAP_FREE_SLOTS_MIN_RATIO, maximum:RUBY_GC_HEAP_FREE_SLOTS_MAX_RATIO.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).RUBY_SHARED_FIBER_POOL_FREE_STACKSโ frees stacks of pooled fibers, if set to1. Do not free the stacks if set to0. Introduced in Ruby 2.7, default:1(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). These environment variables are available since Ruby 2.0.0. All values are specified in bytes.
bestie please read that again ๐ญ lower values = more Fibers/Threads alive but also more chances ofSystemStackErrorandSIGSEGV. It's giving "trade-off", it's giving "pick your poison", it's giving "do not touch this unless you know what you're doing" ๐
RUBY_THREAD_VM_STACK_SIZEโ VM stack size used at thread creation. default:524288(32-bit CPU) or1048576(64-bit).RUBY_THREAD_MACHINE_STACK_SIZEโ Machine stack size used at thread creation. default:524288or1048576.RUBY_FIBER_VM_STACK_SIZEโ VM stack size used at fiber creation. default:65536or131072.RUBY_FIBER_MACHINE_STACK_SIZEโ Machine stack size used at fiber creation. default:262144or524288.
๐ฅ CRASH REPORT ENVIRONMENT ๐ฅ
RUBY_CRASH_REPORTโ the template of the path name where the crash report gets saved, bestie. default: none
๐๏ธ Naming crash report files
Okay so the template can contain % specifiers, and when a crash report file gets created, those specifiers get substituted with these values:
%%โ a single%character.%eโ basename of executable.%Eโ pathname of executable, with slashes (/) replaced by exclamation marks (!).%fโ basename of the program name,$0.%Fโ pathname of the program name,$0, with slashes (/) replaced by exclamation marks (!).%pโ PID of dumped process.%tโ time of dump, expressed as seconds since the Epoch,1970-01-01 00:00:00 +0000(UTC).%NNNโ a character code in octal.
A single % at the end of the template is dropped from the core filename, as is the combination of a % followed by any character other than those listed above. All other characters in the template become a literal part of the core filename. The template may include / characters, which are interpreted as delimiters for directory names.
๐ช Piping crash reports to a program
If the first character of this file is a pipe symbol (|), then the remainder of the line is interpreted as the command-line for a program (or script) that is to be executed.
The pipe template is split on spaces into an argument list before the template parameters are expanded.
๐ MISC ENVIRONMENT ๐
RUBY_TCP_NO_FAST_FALLBACKโ if set to1, disables the fast fallback feature by default inTCPSocket.newandSocket.tcp. When set to0or left unset, the fast fallback feature is enabled. Introduced in Ruby 3.4, default: unset.
๐ 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.
fr fr, do not put security stuff in the public tracker โ it publishes vulnerabilities immediately.
๐ AUTHORS ๐
Ruby is designed and implemented by Yukihiro Matsumoto <matz@netlab.jp>.
See โจhttps://github.com/ruby/ruby/graphs/contributorsโฉ for contributors to Ruby.
๐ That's the whole vibe, bestie โ this page is from the UNIX manual, version RUBY(1), dated April 14, 2018. Now go slay your terminal. โจ
๐ฆ where this page comes from
- centos-stream 10: ruby4.0 4.0.6-37.el10 ยท (Ruby OR BSD-2-Clause) AND (Ruby OR BSD-2-Clause OR GPL-1.0-or-later) AND BSD-3-Clause AND (GPL-3.0-or-later WITH Bison-exception-2.2) AND ISC AND LicenseRef-Fedora-Public-Domain AND MIT AND CC0-1.0 AND zlib AND Unicode-DFS-2015 AND HPND-Markus-Kuhn AND Ruby-pty AND (Ruby OR BSD-2-Clause OR Python-2.0.1) AND BSD-2-Clause AND (Apache-2.0 OR BSL-1.0) AND GPL-2.0-only AND CC-BY-2.5 AND OFL-1.1-RFN AND BSL-1.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms