Class: Opts::ArgumentParser
- Inherits:
-
Object
- Object
- Opts::ArgumentParser
- Defined in:
- lib/opts/argument_parser.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
- #arg(name, options = {}) ⇒ Object
- #call(env, args) ⇒ Object
-
#initialize(app = nil, &block) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
Constructor Details
#initialize(app = nil, &block) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/opts/argument_parser.rb', line 5 def initialize(app=nil, &block) @app = app @args = [] if block and block.arity == -1 instance_eval(&block) elsif block_given? yield(self) end end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
3 4 5 |
# File 'lib/opts/argument_parser.rb', line 3 def app @app end |
Instance Method Details
#arg(name, options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/opts/argument_parser.rb', line 16 def arg(name, ={}) = { :type => :string, :required => true, :min => 1, :max => 1 }.merge() [:max] = nil if .delete(:splat) @args << [name, ] end |
#call(env, args) ⇒ Object
22 23 24 25 26 |
# File 'lib/opts/argument_parser.rb', line 22 def call(env, args) new_env, new_args = env.dup, args.dup parse(new_env, new_args) @app.call(new_env, new_args) end |