class NumRu::Misc::KeywordOptAutoHelp

class NumRu::Misc::KeywordOptAutoHelp < NumRu::Misc::KeywordOpt

Same as class NumRu::Misc::KeywordOpt, but the method #interpret shows a help message and raise an exception if option ‘help’ is provided as an argument and is not nil or false (NumRu::Misc::HelpMessagingException < StandardError or if the arguments cannot be interpreted correctly (ArgumentError). Option ‘help’ is automatically defined, so you do not have to define it yourself.

Public Class Methods

new(*args) click to toggle source
Calls superclass method NumRu::Misc::KeywordOpt::new
# File lib/numru/misc/keywordopt.rb, line 334
def initialize(*args)
  args.push(['help',  false, 'show help message if true'])
  super(*args)
end

Public Instance Methods

interpret(hash) click to toggle source
Calls superclass method NumRu::Misc::KeywordOpt#interpret
# File lib/numru/misc/keywordopt.rb, line 339
def interpret(hash)
  begin
    out = super(hash)
  rescue
    raise $!.inspect + "\n  Available parameters are:\n" + help
  end
  if out['help']
    puts         "<< Description of options >>\n" + help
    puts ' Current values=' + out.inspect
    raise Misc::HelpMessagingException, '** help messaging done **'
  end
  out
end
set(hash) click to toggle source
Calls superclass method NumRu::Misc::KeywordOpt#set
# File lib/numru/misc/keywordopt.rb, line 353
def set(hash)
  raise ArgumentError, "not a hash" if !hash.is_a?(Hash)
  if hash['help']
    puts         "<< Description of options >>\n" + help
    raise Misc::HelpMessagingException, '** help messaging done **'
  end
  super
end