Learn Ruby backticks and the backtick operator for capturing shell output, escaping arguments, and choosing between backticks, system, and exec.
Reference
Kernel Methods
Top-level methods mixed into every Ruby object via Kernel.
- ` (backtick)
- Array
Array is Ruby's primary ordered collection. Create arrays with literal syntax, access by index, push and pop values, and iterate with map, select, and reduce.
- Hash
Kernel#Hash converts its argument to a Hash using the strict to_hash protocol, with special cases for nil and empty arrays, and raises TypeError otherwise.
- Kernel#__dir__
Kernel#__dir__ returns the absolute canonicalized path of the source file's directory, or nil when no source file exists. Works in any Ruby context.
- Kernel#__method__
Kernel#__method__ returns the name of the current method as a Symbol, even when invoked through an alias. Pair it with __callee__ to see the entry point.
- Kernel#abort
Kernel#abort ends a Ruby program right away without running at_exit blocks, writing an optional message to stderr and returning exit code 1 to signal failure.
- Kernel#Array
Convert any object to an Array with Kernel#Array, the Kernel function that calls to_ary, then to_a, and wraps the value when neither is defined.
- Kernel#at_exit
Kernel#at_exit registers a block that Ruby runs when the program ends, executing handlers in reverse order for cleanup like closing files and flushing logs.
- Kernel#autoload
Kernel#autoload defers file loading until a constant is first referenced. Covers module setup, naming conventions, and comparison with require.
- Kernel#caller
Use Kernel#caller to inspect the current execution stack in Ruby, returning an array of file-and-line location strings for debugging and error reporting.
- Kernel#catch
Kernel#catch establishes a block that throw can transfer control into, enabling non-local exits from deeply nested structures in Ruby programs.
- Kernel#chomp
How Kernel#chomp removes trailing record separators from strings in Ruby, with examples for line processing and the difference between chomp and chop.
- Kernel#Complex
Kernel#Complex builds a Complex from two numbers or parses one from a string. Argument forms, the exception: flag, and the gotchas to watch for.
- Kernel#eval
Kernel#eval executes Ruby code from a string within a given binding, enabling metaprogramming, DSL construction, and runtime code generation.
- Kernel#exec
Kernel#exec replaces the Ruby process with an external program, handing off control entirely. Useful for wrapper scripts, launchers, and interpreter switching.
- Kernel#exit
Kernel#exit terminates the Ruby program immediately with a status code so callers can tell whether the run succeeded.
- Kernel#exit!
Kernel#exit! terminates a Ruby process immediately, skipping at_exit handlers and finalizers. Use exit! for fork-safe child cleanup and forced shutdowns.
- Kernel#fail
Raises an exception with Kernel#fail, the historical alias for raise, and shows when teams may choose one form.
- Kernel#Float
Converts an argument to a Float in Ruby — strict parser, raises on bad input, and supports the exception: false keyword to return nil instead.
- Kernel#fork
Use Kernel#fork to create a child process by duplicating the current Ruby process for parallel execution, worker pools, and daemon handling on Unix systems.
- Kernel#format
Kernel#format returns a formatted string using printf-style specifiers for decimal, float, hex, and string output with width, precision, and alignment control.
- Kernel#gets
Kernel#gets reads a line from standard input as a string, returning nil at EOF. Supports custom separators for interactive command-line tools and scripts.
- Kernel#gsub
Kernel#gsub replaces every pattern match in a string, returning a new copy. Accepts regex, block substitution, and hash-based replacements for cleanup.
- Kernel#Integer
Convert objects to Integer with strict validation, supporting strings in any base, radix indicators, and a non-raising exception: false mode.
- Kernel#iterator?
Check if the current kernel method received a block with iterator? in Ruby. Returns true when a block is available for yielding in the active context.
- Kernel#lambda
Kernel#lambda creates an anonymous function with strict argument checking, ideal for callbacks, currying, and composition in Ruby functional programming.
- Kernel#load
Executes Ruby code from a file with Kernel#load, rerunning the file each time and optionally wrapping it in an isolated module.
- Kernel#local_variables
Use Kernel#local_variables in Ruby to inspect the current scope by returning symbols for every local variable name visible at the point of the call.
- Kernel#loop
How Kernel#loop executes a Ruby block repeatedly until break is called, with examples for infinite iterations, retry logic, and explicit termination control.
- Kernel#open
Use the Kernel#open method in Ruby to open files for reading and writing, execute shell commands through pipes, and manage IO streams with automatic cleanup.
- Kernel#p
Use Kernel#p in Ruby to output objects with inspect for debugging. See exact object structure including quotes, types, and nested data unlike puts or print.
- Kernel#pp
Use the Kernel#pp method in Ruby to pretty-print objects to stdout with readable indentation. Ideal for debugging nested arrays, hashes, and custom objects.
- Kernel#present?
Kernel#present? checks whether a Rails object is neither nil nor blank. Use it for readable presence checks on user input and collections.
- Kernel#print
Kernel#print writes objects to stdout without a trailing newline, keeping the cursor on the same line for prompts, progress updates, and incremental output.
- Kernel#printf
Kernel#printf formats and outputs objects to STDOUT using format specifiers, which is useful for tables, reports, and aligned console output.
- Kernel#proc
Kernel#proc creates a new Proc object by capturing the current block for later execution. Unlike lambdas, procs have lenient argument handling.
- Kernel#putc
Kernel#putc writes a single character to STDOUT from a string or integer ASCII code, useful for byte-level output, terminal effects, and low-level file writing.
- Kernel#puts
Kernel#puts writes objects to stdout followed by a newline, making simple Ruby console output easy to read and easy to scan in scripts.
- Kernel#raise
Kernel#raise raises an exception in Ruby and stops normal flow unless a rescue block handles it. Use it for validation, guard clauses, and unexpected failures.
- Kernel#rand
Kernel#rand generates random numbers in Ruby. Without arguments returns a float 0.0-1.0; with an integer returns 0 to n-1; accepts a Range for bounded values.
- Kernel#Rational
Convert a Numeric or String to a Rational in Ruby with Kernel#Rational. Covers the two-argument form, float gotchas, and the exception: keyword.
- Kernel#readlines
Kernel#readlines reads every line from an IO object into a Ruby array of strings, making it easy to filter, sort, or index file content in memory.
- Kernel#require
Kernel#require loads Ruby source files, gems, and standard library modules, tracking what has already been loaded to prevent double-loading across the program.
- Kernel#require_relative
Loads a Ruby file relative to the current file with Kernel#require_relative and keeps local imports easy to read.
- Kernel#sleep
Kernel#sleep suspends the current Ruby thread for a given duration in seconds, supporting fractional timing, indefinite waits, and signal-interrupted returns.
- Kernel#spawn
Kernel#spawn runs an external command in a child process and returns its pid without waiting — use options for env, chdir, umask, and fd redirection.
- Kernel#sprintf
Kernel#sprintf returns a formatted string for reports, labels, and other text that needs controlled spacing, alignment, or numeric formatting.
- Kernel#srand
Kernel#srand seeds the Ruby random number generator so that rand produces repeatable sequences, essential for testing and debugging deterministic programs.
- Kernel#String
Convert any object to a String using Kernel#String, the Kernel module function for explicit string conversion that dispatches through to_str and to_s.
- Kernel#syscall
Kernel#syscall invokes kernel calls by number for low-level system programming. Covers Linux x86_64 examples, portability risks, and safer Ruby alternatives.
- Kernel#system
Kernel#system runs an external command and returns true, false, or nil. Use it when you want the output visible in the terminal.
- Kernel#test
Check file characteristics and permissions with Ruby's Kernel#test and Unix-style operators. Includes practical examples and modern File method alternatives.
- Kernel#then
Kernel#then passes any Ruby object to a block and returns the result, creating fluent transformation pipelines and concise method chaining on any object.
- Kernel#throw
Kernel#throw transfers control to a matching catch block in the call stack, enabling non-local exits from nested loops, deep call stacks, and state machines.
- Kernel#to_f
Use Kernel#to_f to convert values to floating-point numbers in Ruby. Parse numeric data from strings and handle custom object conversion safely.
- Kernel#trace_var
Kernel#trace_var sets a callback that fires when a global variable changes, useful for debugging state changes and monitoring variable access in Ruby programs.
- Kernel#trap
Kernel#trap registers handlers for OS signals like INT and TERM, enabling graceful shutdown, config reload, and custom signal-based communication in Ruby.
- Kernel#warn
Kernel#warn outputs messages to STDERR in Ruby, the idiomatic choice for deprecation notices, conditional alerts, and runtime diagnostics separate from stdout.
- Kernel#yield_self
Kernel#yield_self passes any Ruby object to a block and returns the result, enabling method chaining pipelines and clean transformation steps on any object.
- String
Explore the Ruby String class for text handling, from creating and modifying strings to managing encoding, interpolation, and common string operations.