O'Reilly logo

Ruby in a Nutshell by Yukihiro Matsumoto

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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([ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required