Class: Driskell::Listen::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/driskell-listen/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts, defaults) ⇒ Options

Returns a new instance of Options.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/driskell-listen/options.rb', line 3

def initialize(opts, defaults)
  @options = {}
  given_options = opts.dup
  defaults.keys.each do |key|
    @options[key] = given_options.delete(key) || defaults[key]
  end

  return if given_options.empty?

  msg = "Unknown options: #{given_options.inspect}"
  Driskell::Listen::Logger.warn msg
  fail msg
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_) ⇒ Object



17
18
19
20
21
# File 'lib/driskell-listen/options.rb', line 17

def method_missing(name, *_)
  return @options[name] if @options.key?(name)
  msg = "Bad option: #{name.inspect} (valid:#{@options.keys.inspect})"
  fail NameError, msg
end