Name

Module — Module class

Synopsis

A Module is similar to a class, except that it has no superclass and can’t be instantiated.

Class Methods

Module::class_variables

Returns an array of class variable names.

Module::constants

Returns an array of constant names.

Module::nesting

Returns an array of classes and modules nested at the point of call.

Module::new

Creates a new anonymous module.

Instance Methods

m < mod

Returns true if m is a descendant of mod.

m <= mod

Returns true if m is a descendant of or equal to mod.

m <=> mod

Returns +1 if m is an ancestor of mod, 0 if m is the same as mod, and -1 if m is a descendant of mod.

m === obj

Returns true if obj is an instance of m or one of its descendants.

m > mod

Returns true if m is an ancestor of mod.

m >= mod

Returns true if m is an ancestor of or equal to mod.

m.ancestors

Returns an array of ancestors, including both classes and modules.

m.const_defined?(name)

Returns true if the constant specified by name is defined.

m.const_get(name)

Returns the value of the specified constant.

m.const_set(name, value)

Sets the value of a constant.

m.constants

Returns an array of constant names.

m.included_modules

Returns an array of names of included modules.

m.instance_method(name)

Returns a UnboundMethod object corresponding to name. An exception is raised if the corresponding method doesn’t exist. UnboundMethod should be bound before invocation.

unbound_plus = Fixnum.instance_method(:+)
plus = unbound_plus.bind(1)
p plus.call(2)          # => 3 (1+2)
m.instance_methods([ ...

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.