Class: Slop::Options
- Inherits:
-
Array
- Object
- Array
- Slop::Options
- Defined in:
- lib/slop/options.rb
Instance Method Summary collapse
-
#[](flag) ⇒ Option
The option assoiated with this flag.
- #to_hash(symbols) ⇒ Hash
-
#to_help ⇒ String
All options in a pretty help string.
Instance Method Details
#[](flag) ⇒ Option
Returns the option assoiated with this flag.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/slop/options.rb', line 18 def [](flag) item = flag.to_s if flag.is_a?(Integer) slice flag else find do |option| option.short_flag == item || option.long_flag == item end end end |
#to_hash(symbols) ⇒ Hash
6 7 8 9 10 11 12 13 14 |
# File 'lib/slop/options.rb', line 6 def to_hash(symbols) out = {} each do |option| key = option.key key = key.to_sym if symbols out[key] = option.argument_value end out end |
#to_help ⇒ String
Returns All options in a pretty help string.
31 32 33 34 35 |
# File 'lib/slop/options.rb', line 31 def to_help heads = reject {|x| x.tail } tails = select {|x| x.tail } (heads + tails).map(&:to_s).join("\n") end |