Module: Tins::GO::EnumerableExtension

Includes:
Enumerable
Defined in:
lib/tins/go.rb

Overview

An extension module that provides Enumerable behavior for collecting multiple values associated with the same command-line option.

This extension enables command-line flags like ‘-f foo -f bar` to be collected into a single collection that can be queried via #to_a or #each.

Instance Method Summary collapse

Instance Method Details

#each {|element| ... } ⇒ self

Iterates over each element in the collection.

Implements the Enumerable interface, allowing the use of all Enumerable methods like map, select, find, etc.

Yields:

  • (element)

    Yields each element in the collection

Yield Parameters:

  • element (Object)

    Each element in the collection

Returns:

  • (self)

    Returns self to enable method chaining



52
53
54
55
# File 'lib/tins/go.rb', line 52

def each(&block)
  @arguments.each(&block)
  self
end

#push(argument) ⇒ self Also known as: <<

Adds an element to the collection.

This method allows for chaining operations and collects multiple values for the same command-line option.

Parameters:

  • argument (Object)

    The element to add to the collection

Returns:

  • (self)

    Returns self to enable method chaining



31
32
33
34
35
# File 'lib/tins/go.rb', line 31

def push(argument)
  @arguments ||= []
  @arguments.push argument
  self
end