Class: Opts::OptionParser
- Inherits:
-
Object
- Object
- Opts::OptionParser
- Defined in:
- lib/opts/option_parser.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
- #call(env, args) ⇒ Object
-
#initialize(app = nil, &block) ⇒ OptionParser
constructor
A new instance of OptionParser.
- #opt(name, options = {}) ⇒ Object
Constructor Details
#initialize(app = nil, &block) ⇒ OptionParser
Returns a new instance of OptionParser.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/opts/option_parser.rb', line 5 def initialize(app=nil, &block) @options = {} @short_names = {} @app = app 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/option_parser.rb', line 3 def app @app end |
Instance Method Details
#call(env, args) ⇒ Object
17 18 19 20 21 |
# File 'lib/opts/option_parser.rb', line 17 def call(env, args) new_env, new_args = env.dup, args.dup parse(new_env, new_args) @app.call(new_env, new_args) end |
#opt(name, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/opts/option_parser.rb', line 24 def opt(name, ={}) if short = [:short] @short_names[short.to_s] = name.to_s end @options[name.to_s] = { :type => :boolean }.merge() end |