Appendix A: Kernel methods list

  • callcc: Generates a Continuation object, which it passes to the associated block.
  • eval: Evaluates the Ruby expression(s) in string.
  • lambda: Equivalent to Proc.new, except the resulting Proc objects check the number of parameters passed when called.
  • proc: Equivalent to Proc.new.
  • rand: If called without an argument, or if max.to_i.abs == 0, rand returns a pseudo-random floating point number between 0.0 and 1.0, including 0.0 and excluding 1.0.
  • srand: Seeds the system pseudo-random number generator, Random::DEFAULT, with number.
  • warn: If warnings have been disabled (for example with the -W0 flag), does nothing.

Loading Code

  • autoload: Registers filename to be loaded (using Kernel::require) the first time that module (which may be a String or a symbol) is accessed.
  • autoload?: Returns filename to be loaded if name is registered as autoload.
  • load: Loads and executes the Ruby program in the file filename.
  • require: Loads the given name, returning true if successful and false if the feature is already loaded.
  • require_relative: Ruby tries to load the library named string relative to the requiring file’s path.
  • gem (defined by RubyGems): Use #gem to activate a specific version of gem_name.

Data Conversion

  • Array: Returns arg as an Array.
  • Complex: Returns x+i*y;
  • Float: Returns arg converted to a float.
  • Hash: Converts arg to a Hash by calling arg.to_hash.
  • Integer: Converts arg to an Integer.
  • Rational: Returns x/y or arg as a Rational.
  • String: Returns arg as a String.

Current Context

  • __callee__: Returns the called name of the current method as a Symbol.
  • __dir__: Returns the canonicalized absolute path of the directory of the file from which this method is called.
  • __method__: Returns the name at the definition of the current method as a Symbol.
  • binding: Returns a Binding object, describing the variable and method bindings at the point of call.
  • block_given?: Returns true if yield would execute a block in the current context.
  • caller: Returns the current execution stack—an array containing strings in the form file:line or file:line: in 'method'.
  • caller_locations: Returns the current execution stack—an array containing backtrace location objects.
  • global_variables: Returns an array of the names of global variables.
  • local_variables: Returns the names of the current local variables.

Execution Flow

  • abort:
  • at_exit: Converts block to a Proc object (and therefore binds it at the point of call) and registers it for execution when the program exits.
  • exit: Initiates the termination of the Ruby script by raising the SystemExit exception.
  • exit!: Exits the process immediately.
  • catch: catch executes its block.
  • throw: Transfers control to the end of the active catch block waiting for tag.
  • fail: With no arguments, raises the exception in $! or raises a RuntimeError if $! is nil.
  • raise: With no arguments, raises the exception in $! or raises a RuntimeError if $! is nil.
  • loop: Repeatedly executes the block.
  • sleep: Suspends the current thread for duration seconds (which may be any number, including a Float with fractional seconds).

IO and Strings

  • gets: Returns (and assigns to $_) the next line from the list of files in ARGV (or $*), or from standard input if no files are present on the command line.
  • format: Returns the string resulting from applying format_string to any additional arguments.
  • p: For each object, directly writes obj.inspect followed by a newline to the program’s standard output.
  • print: Prints each object in turn to $stdout.
  • printf: Equivalent to: io.write(sprintf(string, obj, …)) or $stdout.write(sprintf(string, obj, …))
  • putc: Equivalent to: $stdout.putc(int) Refer to the documentation for IO#putc for important information regarding multi-byte characters.
  • puts: Equivalent to $stdout.puts(obj, …)
  • readline: Equivalent to Kernel::gets, except readline raises EOFError at end of file.
  • readlines: Returns an array containing the lines returned by calling Kernel.gets(*sep*) until the end of file.
  • sprintf: Returns the string resulting from applying format_string to any additional arguments.
  • pp Pretty-printing (more detailed version of p).

Files

  • open: Creates an IO object connected to the given stream, file, or subprocess.
  • select: Calls select(2) system call.
  • test: Uses the character cmd to perform various tests on file1 (first table below) or on file1 and file2 (second table).

Tracing Execution

  • set_trace_func: Establishes proc as the handler for tracing, or disables tracing if the parameter is nil.
  • trace_var: Controls tracing of assignments to global variables.
  • untrace_var: Removes tracing for the specified command on the given global variable and returns nil.

Processes and Commands

  • `: Returns the standard output of running cmd in a subshell.
  • exec: Replaces the current process by running the given external command.
  • fork: Creates a subprocess.
  • spawn: spawn executes specified command and return its pid.
  • syscall: Calls the operating system function identified by num and returns the result of the function or raises SystemCallError if it failed.
  • system: Executes command… in a subshell.
  • trap: Specifies the handling of signals.