Class: IDL::OptionList
- Inherits:
-
Object
- Object
- IDL::OptionList
- Defined in:
- lib/ridl/optparse_ext.rb
Defined Under Namespace
Classes: Option
Instance Method Summary collapse
- #define_switch(switch, options = {}, &block) ⇒ Object (also: #for_switch, #switch)
-
#initialize ⇒ OptionList
constructor
Option.
- #to_option_parser(optp, option_holder) ⇒ Object
- #undefine_switch(switch) ⇒ Object
Constructor Details
#initialize ⇒ OptionList
Option
326 327 328 |
# File 'lib/ridl/optparse_ext.rb', line 326 def initialize() @options = {} end |
Instance Method Details
#define_switch(switch, options = {}, &block) ⇒ Object Also known as: for_switch, switch
330 331 332 333 334 335 |
# File 'lib/ridl/optparse_ext.rb', line 330 def define_switch(switch, = {}, &block) switch = switch.to_s raise RuntimeError, "switch types mismatch" if @options.has_key?(switch) && [:type] && [:type] != @options[switch].type @options[switch] ||= Option.new(switch, ) block.call(Option::Configurator.new(@options[switch])) if block_given? end |
#to_option_parser(optp, option_holder) ⇒ Object
344 345 346 347 348 349 350 351 352 353 |
# File 'lib/ridl/optparse_ext.rb', line 344 def to_option_parser(optp, option_holder) @options.each do |sw, op| (arg_list = [sw]) << op.type arg_list.concat(op.description(optp.summary_indent)) optp.on(*arg_list) do |v| op.run(v, option_holder.) end optp.separator '' if op.separator end end |
#undefine_switch(switch) ⇒ Object
339 340 341 342 |
# File 'lib/ridl/optparse_ext.rb', line 339 def undefine_switch(switch) switch = switch.to_s @options.delete(switch) end |