Ruby file

From wikinotes

NOTE:

There is no such thing as ruby packages. Only modules, and namespaces.

shebang

#!/usr/bin/env ruby -w

require/load/autoload

This is how you import the module.
paths can be absolute, or relative from the load path.
(newer versions or ruby include require_relative, which can handle relative imports).

require

The load path can be modified at runtime by adding paths to the global string $:.

require "filename"
require "dir/filename"

# require relative to current file position
require_relative "sub/filename"

load

load behaves like `reload`, and requires the file-extension

load "filename.rb"

autoload

Autload binds a symbol to a require statement.
The load is only performed if the symbol is accessed.

(The imported module is referred to normally, not as a symbol)

autoload :IPAddr, 'ipaddr'

IPAddr.new('192.168.1.1')

You can also load from a specific file

autoload :Compatibility, "active_record/migration/compatibility"

Commandline Arguments

ARGV  # array of cli args

Loaded Files

$LOADED_FEATURES  # list of all loaded .so/.rb files

Reflection