FreeBSD Manual Pages
RUBY(1) Ruby Programmer's Reference Guide RUBY(1) 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] [--crash-report=template] [--] [program_file] [argument ...] DESCRIPTION Ruby is an interpreted scripting language for quick and easy object-ori- ented programming. It has many features to process text files and to do system management tasks (like in Perl). It is simple, straight-forward, and extensible. 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: Interpretive Ruby is an interpreted language, so you don't have to recompile programs written in Ruby to execute them. 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 declara- tions. Variable names denote their scope - global, class, in- stance, or local. Simple syntax Ruby has a simple syntax influenced slightly from Eiffel. 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. 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. Class, inheritance, and methods Being an object-oriented language, Ruby naturally has basic fea- tures like classes, inheritance, and methods. 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. 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 im- plementations 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, without dependence on Unicode. Bignums With built-in bignums, you can for example calculate factor- ial(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. Thus, you can write your applica- tion in your own programming language on top of Ruby. Exception handling As in Java(tm). Direct access to the OS Ruby can use most Unix system calls, often used in system program- ming. Dynamic loading On most Unix systems, you can load object files into the Ruby in- terpreter 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. OPTIONS The Ruby interpreter accepts the following command-line options (switches). They are quite similar to those of perl(1). --copyright --version -0[octal] --CX ddiirreeccttoorryy --E-eenxctoedrinnaglexitnetrenranla[l:internal] ----eixntteerrnnaall--eennccooddiinngg=eennccooddiinngg -F pattern -I directory -K kcode -S -T[level=1] -U -W[level=2] -a --backtrace-limit=num -c --d-debug -e command --h-help -i extension -l -n -p -r library -s -v -w -x[directory] --y-yydebug ----deinsaabbllee--FFEEAATTUURREE --dump=target --verbose --crash-report=template ENVIRONMENT RUBYLIB A colon-separated list of directories that are 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. RUBYPATH A colon-separated list of directories that Ruby searches for Ruby programs when the -S flag is specified. This variable pre- cedes the PATH environment variable. RUBYSHELL The path to the system shell command. This environment variable is enabled for only mswin32, mingw32, and OS/2 platforms. If this variable is not defined, Ruby refers to COMSPEC. RUBY_FREE_AT_EXIT If set, Ruby tries to free all dynamically allocated memories. Introduced in Ruby 3.3, default: unset. RUBY_IO_BUFFER_DEFAULT_SIZE The custom default buffer size of IO::Buffer. RUBY_MAX_CPU The maximum number of native threads used by M:N Threads sched- uler Introduced in Ruby 3.3, default: 8. RUBY_MN_THREADS If set to 1, 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 RUBY_THREAD_TIMESLICE Sets the default thread time slice (thread quantum) in millisec- onds. Introduced in Ruby 3.4, default: 100ms. --help option. Introduced in Ruby 3.0, default: PAGER environment variable. PATH Ruby refers to the PATH environment variable on calling Ker- nel#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 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 re- ferred to as the "process heap". Thus there are at least two possible ways to trigger GC: 1 Reaching the object limit. 2 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: 3 Reaching the old object limit. 4 Reaching the old malloc limit. There are currently 4 possible areas where the GC may be tuned by the fol- lowing 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 of GC.stat_heap. n is a decimal number between 0 and 4. 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 to RUBY_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, de- fault: 2.0 RUBY_GC_HEAP_REMEMBERED_WB_UNPROTECTED_OBJECTS_LIMIT_RATIO Used to calcu- late the remembered_wb_unprotected_objects_limit using a ratio of old_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 exces- sive malloc growth due to RUBY_GC_MAL- LOC_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 increas- ing malloc growth until RUBY_GC_MALLOC_LIMIT_MAX is 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 is 0.0, then use RUBY_GC_HEAP_GROWTH_FACTOR directly. 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, de- fault: 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 to RUBY_GC_OLDMAL- LOC_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 until RUBY_GC_OLD- MALLOC_LIMIT_MAX is 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 to 1. Do not free the stacks if set to 0. Intro- duced 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 System- StackError exceptions and segmentation faults (SIGSEGV). 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. de- fault: 524288 (32-bit CPU) or 1048575 (64-bit) RUBY_THREAD_MACHINE_STACK_SIZE Machine stack size used at thread creation. default: 524288 or 1048575 RUBY_FIBER_VM_STACK_SIZE VM stack size used at fiber creation. de- fault: 65536 or 131072 RUBY_FIBER_MACHINE_STACK_SIZE Machine stack size used at fiber creation. default: 262144 or 524288 CRASH REPORT ENVIRONMENT RUBY_CRASH_REPORT The template of path name to save crash report. de- fault: none Naming crash report files The template can contain % specifiers which are substituted by the follow- ing values when a crash report file is created: %% 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 excla- mation 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 inter- preted as delimiters for directory names. Piping crash reports to a program If the first character of this file is a pipe symbol (|), then the remain- der 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 tem- plate parameters are expanded. MISC ENVIRONMENT RUBY_TCP_NO_FAST_FALLBACK If set to 1, disables the fast fallback feature by default in TCPSocket.new and Socket.tcp. When set to 0 or left unset, the fast fallback feature is enabled. Introduced in Ruby 3.4, de- fault: 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 secu- rity@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 vulnerabili- ties 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. UNIX April 14, 2018 RUBY(1)
NAME | SYNOPSIS | DESCRIPTION | FEATURES | OPTIONS | ENVIRONMENT | GC ENVIRONMENT | STACK SIZE ENVIRONMENT | CRASH REPORT ENVIRONMENT | MISC ENVIRONMENT | SEE ALSO | REPORTING BUGS | AUTHORS
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=ruby34&sektion=1&manpath=FreeBSD+Ports+15.1.quarterly>
