Class: Inventory::Authors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/inventory-1.0/authors.rb

Overview

Contains zero or more authors of the project. Authors can be added and enumerated. Authors are set up by passing a block to #initialize and calling #author inside it.

Examples:

Creating a List of Authors

Authors.new{
  author 'A. U. Thor', '[email protected]'
  author 'W. R. Ither', '[email protected]'
}

Instance Method Summary collapse

Constructor Details

#initialize(*authors) {|?| ... } ⇒ Authors

Creates a new list of AUTHORS and allows more to be added in the optionally #instance_exec’d block by calling #author inside it.

Parameters:

Yields:

  • (?)


20
21
22
23
# File 'lib/inventory-1.0/authors.rb', line 20

def initialize(*authors)
  @authors = authors
  instance_exec(&Proc.new) if block_given?
end

Instance Method Details

#+(other) ⇒ Authors

Returns The authors of the receiver and those of OTHER.

Returns:

  • (Authors)

    The authors of the receiver and those of OTHER



40
41
42
# File 'lib/inventory-1.0/authors.rb', line 40

def +(other)
  self.class.new(*(authors + other.authors))
end

# {|author| ... } ⇒ Object #Enumerator<Author>

Overloads:

  • # {|author| ... } ⇒ Object

    Enumerates the authors.

    Yield Parameters:

  • #Enumerator<Author>

    Returns An Enumerator over the authors.

    Returns:

    • (Enumerator<Author>)

      An Enumerator over the authors



50
51
52
53
54
55
56
# File 'lib/inventory-1.0/authors.rb', line 50

def each
  return enum_for(__method__) unless block_given?
  authors.each do |author|
    yield author
  end
  self
end