Class: Slop::Options
- Inherits:
-
Array
- Object
- Array
- Slop::Options
- Defined in:
- lib/slop/options.rb
Instance Method Summary collapse
-
#[](flag) ⇒ Option
Fetch an Option object.
- #to_hash(symbols) ⇒ Hash
-
#to_help ⇒ String
All options in a pretty help string.
Instance Method Details
#[](flag) ⇒ Option
Fetch an Option object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/slop/options.rb', line 23 def [](flag) if flag.is_a?(Integer) slice flag else item = flag.to_s 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 |
# File 'lib/slop/options.rb', line 6 def to_hash(symbols) reduce({}) do |hsh, option| key = option.key key = key.to_sym if symbols hsh[key] = option.argument_value hsh end end |
#to_help ⇒ String
Returns All options in a pretty help string.
36 37 38 39 40 41 |
# File 'lib/slop/options.rb', line 36 def to_help heads = reject(&:tail) tails = select(&:tail) all = (heads + tails).select(&:help) all.map(&:to_s).join("\n") end |