Class: RProgram::OptionList

Inherits:
Hash
  • Object
show all
Defined in:
lib/rprogram/option_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OptionList

Creates a new OptionList object.

Parameters:

  • options (Hash{Symbol => String}) (defaults to: {})

    The options to start with.



10
11
12
# File 'lib/rprogram/option_list.rb', line 10

def initialize(options={})
  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object (protected)

Provides transparent access to the options within the option list.

Examples:

opt_list = OptionList.new(:name => 'test')
opt_list.name
# => "test"


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rprogram/option_list.rb', line 24

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