RUBY(1)
π RUBY(1) β Ruby Programmer's Reference Guide π
okay bestie, sit down, hydrate, and let me tell you about ruby β this is the manual page for the Ruby interpreter, from the Ruby Programmer's Reference Guide, and yes it's a whole vibe. π¦
β¨ NAME β¨
ruby β Interpreted object-oriented scripting language π
πΈ 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 ...]
yes that's a lot of flags, and yes, we're gonna get to every single one of them eventually. not today, but eventually. bestie patience. π«Ά
π DESCRIPTION π
Ruby is an <strong>interpreted scripting language for quick and easy object-oriented programming</strong>.</purgle>
Let me fix that β Ruby is an interpreted scripting language for quick and easy object-oriented programming. β¨ It's got a whole arsenal of features for processing text files and for doing system management tasks (like in Perl, iykyk). It is simple, straightforward, and extensible. periodt. π
So like β if you want a language for easy object-oriented programming, or you're just not feeling the Perl ugliness π, or you DO love the concept of LISP but the parentheses are giving you a migraine β Ruby might be your language of choice. π
π FEATURES π
Ruby's features are as follows, and honestly? the way this list just keeps going. main character energy fr fr. π
π§ Interpretive
Ruby is an interpreted language, so you don't have to recompile programs written in Ruby to execute them. no build step bestie, we just run it. slay. β¨
π¦ Variables have no type (dynamic typing)
Variables in Ruby can contain data of any type. You don't have to worry about variable typing. Consequently, it has a weaker compile time check. π
πΈ No declaration needed
You can use variables in your Ruby programs without any declarations. Variable names denote their scope β global, class, instance, or local. π
π Simple syntax
Ruby has a simple syntax influenced slightly from Eiffel. cute, cultured, well-read. π
π 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. you will not be calling free() bestie, she's got it handled. π«Ά
β Everything is an object
Ruby is a purely object-oriented language, and was so <strong>since its creation</strong>. Even such basic data as integers are seen as objects. yes even the humble integer. iconic behavior. π
π Class, inheritance, and methods
Being an object-oriented language, Ruby naturally has basic features like classes, inheritance, and methods. the classics. π
π§ 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 β if you're feeling spicy β you can make up your own prototype based object system using singleton methods. go off. π
π Mix-in by modules
Ruby intentionally does not have the multiple inheritance, because it is a source of confusion. we don't do chaos here (affectionate). 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. πΈ
β¨ Closures
In Ruby, you can objectify the procedure. π«Ά
π Text processing and regular expressions
Ruby has a 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, <strong>without dependence on Unicode</strong>. the way that it just does this. obsessed. π
π Bignums
With built-in bignums, you can for example calculate <code>factorial(400)</code>. go ahead, try it, she's not scared. π₯
π Reflection and domain specific languages
<strong>Class is also an instance of the <code>Class</code> class.</strong> Definition of classes and methods is an expression just as <code>1+1</code> 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. it's giving meta. it's giving inception. it's giving slay. π
π§ Exception handling
As in Java(tm). π
π Direct access to the OS
Ruby can use most Unix system calls, often used in system programming. π¦
β 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 <code>gem(1)</code> command. π«Ά
Visit RubyGems.org (<code>https://rubygems.org/</code>) to find the gems you need, and explore GitHub (<code>https://github.com/</code>) to see how they are being developed and used. π
okay that's part 1 bestie, the flags are coming and there are SO many of them, stay with me πΈ
β¨ OPTIONS β¨
okay bestie, so the Ruby interpreter takes all these command-line options (we call 'em switches), and ngl they're pretty similar to perl(1)'s. Here's the whole menu, no skips π
--copyrightβ prints the copyright notice and dips immediately, without running any script. iconic legal moment β¨--versionβ prints the version of the Ruby interpreter and quits right away, no script running. just vibes and a number π-0[octal]β (that's the digit βzeroβ, bestie, don't get it twisted π) 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, no problem.-00turns Ruby into paragraph mode πΈ. And-0777makes Ruby read the whole file at once as one single string, because there's literally no legal character with that value. slay.-C directory,-X directoryβ makes Ruby switch to that directory. like a lilcdbut for Ruby's soul π¦-E external[:internal],--encoding external[:internal]β sets the default value(s) for external encodings and internal encoding. Separate the values with a colon (:).
You can totally leave out the internal one β then the value (Encoding.default_internal) will be nil. no notes π
--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 ($:). path = loaded π-K kcodeβ sets the KANJI (Japanese) encoding. The default for script encodings (__ENCODING__) and external encodings (Encoding.default_external) becomes whatever you pick.kcodecan be one of:eβ EUC-JPsβ Windows-31J (CP932)uβ UTF-8nβ ASCII-8BIT (BINARY)
-Sβ makes Ruby use thePATHenvironment variable to hunt down 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 hold the full pathname, so you need the -S switch to tell Ruby to search for the script when necessary (to handle embedded spaces and all that jazz). A better construct than $* would be ${1+"$@"}, but it doesn't work if the script is being interpreted by csh(1). RIP π«Ά
-T[level=1]β turns on taint checks at the specified level (default is1). safety first, bestie π₯-Uβ sets the default value for internal encodings (Encoding.default_internal) to UTF-8. as it should be π-W[level=2]β turns on verbose mode at the specified level without printing the version message at the start. 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. automatic, no cap β¨
-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. we love a syntax girly π-d,--debugβ turns on debug mode.$DEBUGgets set totrue. π-e commandβ specifies the script straight 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. the classic "help me" bestie π-i extensionβ sets 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 secured, original preserved, both files living their truth π
-lβ (that's the lowercase letter βellβ, bestie π) enables automatic line-ending processing, which means: first it sets$\to the value of$/, and second it chops every line read usingchomp!.-nβ makes Ruby assume this loop wraps around your script, so it iterates over the file name arguments kinda likesed -norawk:
while gets
...
end
-pβ acts mostly the same as-n, except it prints the value of the variable$_at the end of each loop. For example:
% echo matz | ruby -p -e '$_.tr! "a-z", "A-Z"'
MATZ
obsessed with how clean that is π
-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 it finds there get 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 prints its version at the start and sets the variable$VERBOSEtotrue. Some methods print extra messages when this variable is true. And heads up: if you give this switch and no other switches are present, Ruby quits right after printing its version. dramatic exit, respect β¨-wβ enables verbose mode without printing the version message at the beginning. It sets the$VERBOSEvariable totrue.-x[directory]β tells Ruby 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 must be specified with eitherEOF,^D(control-D),^Z(control-Z), or the reserved word__END__. If you specify a directory name, Ruby switches to that directory before executing the script. π§-y,--yydebugβ DO NOT USE. π¨
Turns on compiler debug mode. Ruby will print a whole bunch of internal state messages during compilation. Only specify this switch if you're actually going to debug the Ruby interpreter. like, fr fr, don't just casually use this one bestie π
--disable-FEATURE,--enable-FEATUREβ disables (or enables) the specifiedFEATURE. Here's the roster:--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,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 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 heads up: if you give this switch and there are no script arguments (no script file or-eoptions), Ruby quits immediately. π¦
πΈ 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 gets 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, andOS/2platforms. 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 bestie, gather round, we're talking about the garbage collector π«Ά The Ruby GC tracks objects in fixed-sized slots, but each object can also 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, which people usually call the "process heap". So basically 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 showed up (iconic behaviour tbh) and the limits got split into young and old generations, which gives us 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 can 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 of slots if there are not 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β The allocation rate is limited to this number of slots, which prevents excessive allocation caused byRUBY_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 caused byRUBY_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, which reduces GC frequency but increases 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 caused byRUBY_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, which reduces full GC frequency but increases malloc growth untilRUBY_GC_OLDMALLOC_LIMIT_MAXis reached. Introduced in Ruby 2.1, default:1.2, minimum:1.0(no growth).
π§΅ STACK SIZE ENVIRONMENT π§΅
ngl bestie, these ones are a whole vibe check you have to be careful with. 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 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 allow applications to keep more Fibers or Threads running β but it increases the chance of SystemStackError exceptions and segmentation faults (SIGSEGV) π These environment variables have been 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:131072(32-bit CPU) or262144(64-bit).RUBY_THREAD_MACHINE_STACK_SIZEβ Machine stack size used at thread creation. default:524288or1048575.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.
π 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/).
ok but do NOT report security vulnerabilities via this system, because it publishes the vulnerabilities immediately. no cap. π
π 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. π
and that's the whole page bestie, you ate that π this one's from the UNIX manual, dated April 14, 2018, and it lives at RUBY(1) β go forth and slay your Ruby β¨π¦π
π¦ where this page comes from
- ubuntu jammy: ruby3.0 3.0.2-7ubuntu2 Β· BSD-2-Clause OR Ruby
- ubuntu jammy: ruby3.0 3.0.2-7ubuntu2.13 Β· 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