Class: Slop::Options

Inherits:
Array
  • Object
show all
Defined in:
lib/slop/options.rb

Instance Method Summary collapse

Instance Method Details

#[](flag) ⇒ Option

Returns the option assoiated with this flag.

Parameters:

  • flag (Object)

    The short/long flag representing the option

Returns:

  • (Option)

    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

Parameters:

  • symbols (Boolean)

    true to cast hash keys to symbols

Returns:

  • (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_helpString

Returns All options in a pretty help string.

Returns:

  • (String)

    All options in a pretty help string

See Also:



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