Method: CP::Option#initialize

Defined in:
lib/cp/option.rb

#initialize(*args) {|_self| ... } ⇒ Option

see: OptionsParser#make_switch

Yields:

  • (_self)

Yield Parameters:

  • _self (CP::Option)

    the object that the method was called on



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cp/option.rb', line 9

def initialize( *args )
  @required = false
  parsed = parse_args( args )

  yield self if block_given?

  # pick up any args we dropped the first time
  parse_args( self.to_option_parser_args + args ) unless parsed

  unless self.short || self.long
    raise ArgumentError.new( "no switch given" )
  end
end