Module: AbstractType::ClassMethods

Defined in:
lib/abstract_type.rb

Instance Method Summary collapse

Instance Method Details

#abstract_method(*names) ⇒ self

Create abstract instance methods

Examples:

class Foo
  include Abstract

  # Create an abstract instance method
  abstract_method :some_method
end

Parameters:

  • names (Array<#to_s>)

Returns:

  • (self)


57
58
59
60
# File 'lib/abstract_type.rb', line 57

def abstract_method(*names)
  names.each { |name| create_abstract_instance_method(name) }
  self
end

#abstract_singleton_method(*names) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create abstract singleton methods

Examples:

class Foo
  include Abstract

  # Create an abstract instance method
  abstract_singleton_method :some_method
end

Parameters:

  • names (Array<#to_s>)

Returns:

  • (self)


77
78
79
80
# File 'lib/abstract_type.rb', line 77

def abstract_singleton_method(*names)
  names.each { |name| create_abstract_singleton_method(name) }
  self
end

#newObject

Instantiate a new object

Ensures that the instance cannot be of the abstract type and must be a descendant.

Examples:

object = AbstractType.new

Returns:

  • (Object)


34
35
36
37
38
39
40
# File 'lib/abstract_type.rb', line 34

def new(*)
  if superclass.equal?(Object)
    raise NotImplementedError, "#{inspect} is an abstract type"
  else
    super
  end
end