Executes shell commands and returns the output as a string
Reference
Kernel Methods
Top-level methods mixed into every Ruby object via Kernel.
- ` (backtick)
- Array
The core ordered collection class in Ruby, holding indexed objects of any type.
- Kernel#abort
Terminates the program immediately, outputting an optional error message to stderr and returning a failure exit code.
- Kernel#at_exit
Registers a block to be executed when the Ruby program exits, after all other shutdown code.
- Kernel#autoload
Sets up lazy loading for a constant, loading the file only when the constant is first referenced.
- Kernel#caller
Returns the current call stack as an array of location strings, useful for debugging.
- Kernel#catch
Creates a block that can be intercepted by throw, providing non-local flow control.
- Kernel#chomp
Removes trailing characters from a string. chomp removes record separators while chop removes any trailing character.
- Kernel#eval
Evaluates Ruby code string in the current context, allowing dynamic code execution.
- Kernel#exec
Replaces the current process with a new program, terminating the Ruby process.
- Kernel#exit
Terminates the Ruby program immediately with the specified exit status code.
- Kernel#exit!
Immediately terminates the process without running exit handlers, ensuring immediate shutdown.
- Kernel#fail
Raises an exception, exactly identical to raise. The fail keyword is a historical alias provided for stylistic preference.
- Kernel#fork
Creates a child process by duplicating the current process, enabling parallel execution.
- Kernel#format
Returns a formatted string using format specifiers, the programmatic equivalent of sprintf.
- Kernel#gets
Reads the next line from standard input, returning nil at EOF. Supports custom separators.
- Kernel#gsub
Replaces all occurrences of a pattern in a string. Returns a new string with every match replaced.
- Kernel#iterator?
Returns true if a block is currently being evaluated, indicating execution is within an iterator.
- Kernel#lambda
Creates an anonymous function (lambda) that behaves like a closure with strict argument checking
- Kernel#load
Executes Ruby code from a file, loading and evaluating the file's contents in the current context.
- Kernel#local_variables
Returns an array of symbols representing local variable names in the current scope.
- Kernel#loop
Executes a block repeatedly until break is called. Use loop for infinite iterations where you explicitly control termination.
- Kernel#open
Opens a file or creates an IO stream, returning a file object or allowing command execution via pipe.
- Kernel#p
Outputs objects to STDOUT using inspect, useful for debugging to see object structure.
- Kernel#pp
Writes objects to stdout in pretty-printed format, returning the objects unchanged
- Kernel#present?
Checks if an object is present, meaning it is neither nil nor blank.
- Kernel#print
Writes objects to stdout without appending a newline
- Kernel#printf
Formats and outputs objects to STDOUT using format specifiers, similar to C's printf.
- Kernel#proc
Creates a new Proc object, capturing the current block for later execution. Unlike lambdas, procs have lenient argument handling.
- Kernel#putc
Outputs a single character to STDOUT, writing only one character at a time.
- Kernel#puts
Writes objects to stdout followed by a newline
- Kernel#raise
Raises an exception, halting program flow unless caught
- Kernel#rand
Generates a random number. Without arguments, returns a float between 0 and 1. With an integer, returns an integer from 0 to n-1. Can also accept a Range.
- Kernel#readlines
Reads all lines from an IO object and returns them as an array of strings.
- Kernel#require
Loads and executes the named Ruby source file, returning true if the file was loaded or was already loaded, false if the file was not found.
- Kernel#require_relative
Loads a Ruby file using a path relative to the current file's location.
- Kernel#sleep
Suspends program execution for the specified number of seconds. Returns the number of seconds actually slept, or nil if interrupted.
- Kernel#sprintf
Returns a string formatted according to the given format string.
- Kernel#srand
Seeds the random number generator, enabling reproducible random sequences.
- Kernel#syscall
Calls system calls directly by number, allowing low-level operating system interaction.
- Kernel#system
Executes an external command as a subprocess and returns true, false, or nil depending on the command's exit status.
- Kernel#test
Tests file characteristics and permissions using Unix file test operators.
- Kernel#then
Passes the object to a block and returns the block result, enabling method chaining on any object.
- Kernel#throw
Transfers control to a corresponding catch block, used for non-local exits.
- Kernel#to_f
Converts a value to a floating-point number, extracting numeric value from strings.
- Kernel#trace_var
Sets a tracer callback for global variables, executing code when the variable is modified.
- Kernel#trap
Sets signal handlers, allowing your program to respond to OS-level signals like interrupts.
- Kernel#warn
Outputs warnings to STDERR, useful for displaying deprecation notices and runtime warnings.
- Kernel#yield_self
Yields the object to a block and returns the block's result, enabling method chaining on any object.
- String
The core class for handling text data, sequences of characters encoded in UTF-8.