prev - up - next - index

Module

The class of the modules.

SuperClass:

Object

Methods:

attr(name[, public])

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 public 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

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.

Class Methods:

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.

method_defined?(id)

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

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.

private(name...)

Makes the method to be called in the function style. Do nothing if the method is already `private'.

public(name...)

Makes the method to be called in the any style. Do nothing if the method is already `public.

Example:

def foo() 1 end
foo
       => 1
self.foo
       => 1

def bar() 2 end
private :bar
bar
       => 2
self.bar
       error--> private method `bar' called for "main"(Object)

Module Baz
  def baz() 3 end
  module_function :baz
end
Baz.baz
       => 3
include Baz
baz
       => 3
self.baz
       error--> private method `baz' called for "main"(Object)

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

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


prev - up - next - index

matz@caelum.co.jp