Module: Sinclair::OptionsParser

Included in:
Sinclair, MethodDefinition
Defined in:
lib/sinclair/options_parser.rb

Overview

Concern for easily adding options

Examples:

class Sinclair
  class OptionsParser::Dummy
    include OptionsParser

    def initialize(options)
      @options = options.deep_dup
    end
  end

  def the_method
    return 'missing option' if options_object.switch.nil?

    if options_object.switch
      "The value is #{options_object.option_1}"
    else
      "The value is not #{options_object.option_1} but #{options_object.option_2}"
    end
  end
end

Author:

  • darthjee

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsHash (readonly)

Options hash

Returns:

  • (Hash)


40
41
42
# File 'lib/sinclair/options_parser.rb', line 40

def options
  @options
end

Instance Method Details

#options_objectOpenStruct

Builds an openstruct of the Hash

Returns:

  • (OpenStruct)


48
49
50
# File 'lib/sinclair/options_parser.rb', line 48

def options_object
  @options_object ||= OpenStruct.new options
end