Class: OptParse2::Builder
- Inherits:
-
Object
- Object
- OptParse2::Builder
- Defined in:
- lib/optparse2/builder.rb
Instance Method Summary collapse
- #block(&block) ⇒ Object
- #build! ⇒ Object
- #default(value = novalue=true, description: nodescription=true, &block) ⇒ Object
- #hidden(hidden = true) ⇒ Object
-
#initialize(positional, block, optparse2) ⇒ Builder
constructor
A new instance of Builder.
- #key(key) ⇒ Object
- #required(required = true) ⇒ Object
Constructor Details
#initialize(positional, block, optparse2) ⇒ Builder
Returns a new instance of Builder.
7 8 9 10 |
# File 'lib/optparse2/builder.rb', line 7 def initialize(positional, block, optparse2) @positional, @block, @optparse2 = positional, block, optparse2 @args = {} end |
Instance Method Details
#block(&block) ⇒ Object
16 17 18 19 20 |
# File 'lib/optparse2/builder.rb', line 16 def block(&block) raise LocalJumpError unless defined? yield @block = block self end |
#build! ⇒ Object
12 13 14 |
# File 'lib/optparse2/builder.rb', line 12 def build! @optparse2.on(*@positional, **@args, &@block) end |
#default(value = novalue=true, description: nodescription=true, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/optparse2/builder.rb', line 27 def default(value = novalue=true, description: nodescription=true, &block) if novalue.nil? != block.nil? raise ArgumentError, "Exactly one of a positional argument or a block can be given" end @args[:default] = (novalue ? block : proc { value }) @args[:default_description] = description unless nodescription self end |
#hidden(hidden = true) ⇒ Object
22 23 24 25 |
# File 'lib/optparse2/builder.rb', line 22 def hidden(hidden = true) @args[:hidden] = hidden self end |
#key(key) ⇒ Object
37 38 39 40 |
# File 'lib/optparse2/builder.rb', line 37 def key(key) @args[:key] = key self end |
#required(required = true) ⇒ Object
42 43 44 45 |
# File 'lib/optparse2/builder.rb', line 42 def required(required = true) @args[:required] = required self end |