Sha256: 7819c088af8f194b0f7413ceec537585917b2210b7b013f5fd348e8587c5f9b5

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

module RProgram
  class OptionList < Hash

    #
    # Creates a new OptionList object.
    #
    # @param [Hash{Symbol => String}] options The options to start with.
    #
    def initialize(options={})
      super(options)
    end

    protected

    #
    # Provides transparent access to the options within the option list.
    #
    # @example
    #   opt_list = OptionList.new(:name => 'test')
    #   opt_list.name
    #   # => "test"
    #
    def method_missing(sym,*args,&block)
      name = sym.to_s

      unless block
        if (name =~ /=$/ && args.length == 1)
          return self[name.chop.to_sym] = args.first
        elsif args.empty?
          return self[sym]
        end
      end

      return super(sym,*args,&block)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rprogram-0.1.7 lib/rprogram/option_list.rb