Class: DefaultOptions::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/default_options/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(orides, &block) ⇒ Parser

Returns a new instance of Parser.



3
4
5
6
7
# File 'lib/default_options/parser.rb', line 3

def initialize(orides, &block)
  @defaults = {}
  overrides(orides.dup)
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/default_options/parser.rb', line 13

def method_missing(method_name, *args)
  if args.size > 0
    @defaults[method_name] = args.first
  else
    if @overrides.has_key? method_name
      @overrides[method_name]
    else
      @defaults[method_name]
    end
  end
end

Instance Method Details

#overrides(orides) ⇒ Object



9
10
11
# File 'lib/default_options/parser.rb', line 9

def overrides(orides)
  @overrides = orides
end