class Argy::Options

The resulting options that were parsed from the command line. @example Getting a value

options = Options.new(foo: "bar")
options.foo #=> "bar"

@example Querying for a value's truthiness

options = Options.new(foo: "bar")
options.foo? #=> true

Public Class Methods

new(values) click to toggle source

Create a new Options @param values [Hash{Symbol => Object}]

# File lib/argy/options.rb, line 12
def initialize(values)
  @values = values
end

Public Instance Methods

[](key) click to toggle source

Get a value by key @see Hash#[]

# File lib/argy/options.rb, line 24
def [](key)
  @values[key]
end
fetch(*args, &block) click to toggle source

Fetch a value by key or provide a default. @see Hash#fetch

# File lib/argy/options.rb, line 30
def fetch(*args, &block)
  @values.fetch(*args, &block)
end
to_h() click to toggle source

The values as a hash @return [Hash{Symbol => Object}]

# File lib/argy/options.rb, line 18
def to_h
  @values
end

Private Instance Methods

method_missing(meth, *args) click to toggle source
Calls superclass method
# File lib/argy/options.rb, line 40
def method_missing(meth, *args)
  query = meth[-1] == "?"
  key = query ? meth[0..-2].to_sym : meth.to_sym

  return super unless @values.key?(key)

  unless args.empty?
    raise ArgumentError, "wrong number of arguments (given #{args.length}, expected 0)"
  end

  query ? !!@values[key] : @values[key]
end
respond_to_missing?(meth, *) click to toggle source
Calls superclass method
# File lib/argy/options.rb, line 36
def respond_to_missing?(meth, *)
  @values.key?(meth.to_s.sub(/\?$/, "").to_sym) || super
end