Module

The module class.

attr_accessor(name ... )

Defines both the read and write methods for the attribute name, where name is specified by Symbol or a string.

The definition of the method defined by attr_accessor is as follows:

def name
  @name
end
def name=(val)
  @name = val
end

attr_reader(name ... )

Defines the read method for the attribute name, where name is specified by Symbol or a string.

The definition of the method defined by attr_reader is as follows:

def name
  @name
end

attr_writer(name ... )

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

Defines the write method for the attribute name (name=), where name is specified by Symbol or a string.

The definition of the method defined by attr_writer is as follows:

def name=(val)
  @name = val
end

include(module ... )

Includes the specified modules' properties (methods and constants). Returns self. include is used to implement a mix-in in place of a multiple inheritance.

class C
  include FileTest
  include Math
end

Module capabilities are included by inserting modules into a class inheritance. Therefore, when searching for methods, included modules will be given priority over superclasses.

If the same module is included two or more times, the second and later instances will be ignored. Furthermore, executing an include that results in a recursive module inheritance will throw an ArgumentError exception.

Last updated