class Ame::Types::Enumeration

Enumeration type for limiting a Symbol argument to one in a fixed set. It also has a {#default}, which will be the first symbol passed to its constructor. @example Using an Enumeration

class Git::CLI::Git::FormatPatch < Ame::Class
  switch '', 'thread', 'STYLE', nil,
    Ame::Types::Enumeration[:shallow, :deep],
    'Controls addition of In-Reply-To and References headers'

Attributes

default[R]

@return [Symbol] The Symbol to use if no argument has been given

Public Class Methods

new(first, second, *rest) click to toggle source

Creates an Enumeration of valid Symbols FIRST, SECOND, and REST for an argument and sets {#default} to FIRST. @param [#to_sym] first @param [#to_sym] second @param [#to_sym, …] rest

# File lib/ame-1.0/types/enumeration.rb, line 21
def initialize(first, second, *rest)
  @default = first
  @names = ([first, second] + rest).map(&:to_sym)
end

Public Instance Methods

parse(argument) click to toggle source

@api internal @param [String] argument @return [Symbol] The result of ARGUMENT#to_sym @raise [MalformedArgument] If ARGUMENT#to_sym isn’t included among the

valid Symbols
# File lib/ame-1.0/types/enumeration.rb, line 31
def parse(argument)
  @names.include?(s = argument.to_sym) ? s :
    raise(Ame::MalformedArgument, 'must be one of %s, not %s' %
          [@names.join(', '), argument])
end