Class: Okay::SimpleOpts

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/okay/simple_opts.rb

Overview

An OptionParser wrapper providing a few convenience functions.

Instance Method Summary collapse

Constructor Details

#initialize(*args, defaults: nil) ⇒ SimpleOpts

Returns a new instance of SimpleOpts.



10
11
12
13
# File 'lib/okay/simple_opts.rb', line 10

def initialize(*args, defaults: nil)
  super(*args)
  @okay_options = defaults || {}
end

Instance Method Details

#parse(args) ⇒ Object



26
27
28
29
# File 'lib/okay/simple_opts.rb', line 26

def parse(args)
  parse!(args.dup)
  @okay_options
end

#simple(*args) ⇒ Object

simple(…, :a) simple(…, :b)

==

options = {} on(…) { |val| options = val } on(…) { |val| options = val }



21
22
23
24
# File 'lib/okay/simple_opts.rb', line 21

def simple(*args)
  key = args.pop
  on(*args) { |*x| @okay_options[key] = x[0] }
end