Module: CP::Has::Options

Included in:
App, Command
Defined in:
lib/cp/has/options.rb

Instance Method Summary collapse

Instance Method Details

#option(*args) {|opt| ... } ⇒ Object

Yields:

  • (opt)


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

def option( *args )
  opt = CP::Option.new( *args )
  yield opt if block_given?

  if( respond_to?( :ancestors, true ) )
    parent_opt = ancestors[1..-1].reverse.inject( {} ) { |opts, c|
      opts.merge( c.options )
    }[opt.name]

    opt = parent_opt.merge( opt ) if parent_opt
  end

  options[opt.name] = opt
  opt
end

#optionsObject



4
5
6
7
# File 'lib/cp/has/options.rb', line 4

def options
  @options ||= {}
  @options
end