The Top-Level Environment

When the Ruby interpreter starts, a number of classes, modules, constants, and global variables and global functions are defined and available for use by programs. The subsections that follow list these predefined features.

Predefined Modules and Classes

When the Ruby 1.8 interpreter starts, the following modules are defined:

Comparable      FileTest        Marshal         Precision
Enumerable      GC              Math            Process
Errno           Kernel          ObjectSpace     Signal

These classes are defined on startup:

Array           File            Method          String
Bignum          Fixnum          Module          Struct
Binding         Float           NilClass        Symbol
Class           Hash            Numeric         Thread
Continuation    IO              Object          ThreadGroup
Data            Integer         Proc            Time
Dir             MatchData       Range           TrueClass
FalseClass      MatchingData    Regexp          UnboundMethod

The following exception classes are also defined:

ArgumentError           NameError               SignalException
EOFError                NoMemoryError           StandardError
Exception               NoMethodError           SyntaxError
FloatDomainError        NotImplementedError     SystemCallError
IOError                 RangeError              SystemExit
IndexError              RegexpError             SystemStackError
Interrupt               RuntimeError            ThreadError
LoadError               ScriptError             TypeError
LocalJumpError          SecurityError           ZeroDivisionError

Ruby 1.9 adds the following modules, classes, and exceptions:

BasicObject     FiberError      Mutex           VM
Fiber           KeyError        StopIteration

You can check the predefined modules, classes, and exceptions in your implementation with code like this:

# Print all modules (excluding classes) puts {|x| eval(x.to_s).instance_of? Module} # Print all classes (excluding exceptions) ...

Get The Ruby Programming Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.