prev - up - next - index

Module

The class of the modules.

SuperClass:

Object

Methods:

self < other
self <= other
self > other
self >= other

Comparison operators. self > other returns true, if self is the superclass or included modules of the other.

self === obj

Returns true, if obj is the instance of the self, or its descendants. That means case can be used for type check for for classes or modules.

alias_method(new,old)

Gives alias to methods. Differences between this method and alias are:

  • specifies method by String or ID (Integer).
  • no global variable aliasing by this method.

append_features(module_or_class)

Append features (mothods and constants) to the receiver. Module#include is defined using this method.

attr(name[, assignable])

Defines new attribute and its access method to read, which are named `name' to the module. The access method definition is like this:

def attr; @attr; end

The optional second argument assignable is given, and its value is true, then the write method to the attribute is also defined. The write access method definition is like this:

def attr=(val); @attr = val; end

By re-defining the access method, accessing attribute can be altered. For example, defining the write access method like below, the assigned value can be printed.

attr("test", true)
def test=(val)
  print("test was ", @test, "\n")
  print("and now is ", @test = val, "\n")
end

attr_reader(name, ...)

Defines the reader method for the specified attribute(s).

attr_writer(name, ...)

Defines the writer method for the specified attribute(s).

attr_accessor(name, ...)

Defines both reader and writer methods for the specified attribute(s).

ancestors

Returns the list of the modules include in the receiver.

class_eval(src)
class_eval{...}

The aliass to the module_eval.

constants

Returns an array that holds names of the constants defined in the receiver.

const_get(name)

Returns the value of the specified constant. When specified constant is not defined, the NameError exception be raised.

const_set(name, value)

Defines the specified constant in the module. If the specified constant is already defined, the NameError exception is raised.

extend_object(object)

Append features (mothods and constants) to the specified object. Object#extend is defined using this method, so that redefining this method overrides extention behavior for the module.

include(module...)

Includes the modules specified to add methods and constants to the receiver module or class. include is for the Mix-in, which is disciplined multiple inheritance.

included_modules

Returns the list of the modules include in the receiver.

instance_methods

Returns the names of the public methods defined in the receiver.

method_added(id)

Will be called when a method defined for the receiver.

method_defined?(id)

Returns true, if the instance of the Module has the method specified by the id.

module_eval(expr)
module_eval{...}

Evaluates the expr string in the module's context. If block supplied for the method, the block is evaluated under the module's context.

In module_eval()'s context:

  • self
  • instance variables
  • constants
  • method definitions
are treated as if it appears in the module's definition body. But local variables are shared with eval()'s outer scope.

module_function(name...)

Makes the methods specified by names into `module function's. the module functions are the method which is also the singleton method of a module (or a class). For example, methods defined in the Math module are the module functions.

name()

Returns the module's name.

private(name...)

If no argument is supplied, changes the default visibility in the class/method definition as private.

Examples:

module Foo
  def foo1() 1 end	# the default is the public
  private		# the default changed to private
  def foo2() 2 end	# foo2 is the private method
end

foo = Foo.new
foo.foo1
       => 1
foo.foo2
       error--> private method `foo2' called #<Foo:0x4011ad8c>(Foo)

With the arguments, it makes the specified methods to be private.

private_instance_methods

Returns the names of the private methods defined in the receiver.

protected(name...)

If no argument is supplied, changes the default visibility in the class/method definition as public, where `protected' means the method can only be called from the method defined in the same class or its subclass. The check will be done in run-time, not compile-time.

With the arguments, it makes the specified methods to be protected.

public [name...]

If no argument is supplied, changes the default visibility in the class/method definition as public.

With the arguments, it makes the specified methods to be private.

Exapmles:

def foo() 1 end
foo
       => 1
self.foo	# the toplevel default is private
       error--> private method `foo' called for "main"(Object)

def bar() 2 end
public :bar	# visibility changed (all access allowed)
bar
       => 2
self.bar
       => 2

private_class_method(name, ...)
public_class_method(name, ...)

Changes visibility of the class methods (class's singleton methods).

remove_const(name)

Removes definition of the named constant. Raises NameError, if specified constant is not defined in the module. Some constants defined in the Object class, like predefined classes are not allowed to be removed, so removing these constants raises NameError also.

remove_method(name)

Removes the named method from the module. Raises NameError, if specified method is not defined in the module.

undef_method(name)

Cancels the method definition specified by name, which is the string or ID (Integer).

Class Methods:

nesting

Returns the nesting of the class/module definitions at the calling point.

new

Creates an anonymous module.


prev - up - next - index

[email protected]