Class: Listen::Options

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

Instance Method Summary collapse

Constructor Details

#initialize(opts, defaults) ⇒ Options

Returns a new instance of Options.


5
6
7
8
9
10
11
12
13
# File 'lib/listen/options.rb', line 5

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

  given_options.empty? or raise ArgumentError, "Unknown options: #{given_options.inspect}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_) ⇒ Object


20
21
22
23
# File 'lib/listen/options.rb', line 20

def method_missing(name, *_)
  respond_to_missing?(name) or raise NameError, "Bad option: #{name.inspect} (valid:#{@options.keys.inspect})"
  @options[name]
end

Instance Method Details

#respond_to_missing?(name, *_) ⇒ Boolean

rubocop:disable Lint/MissingSuper

Returns:

  • (Boolean)

16
17
18
# File 'lib/listen/options.rb', line 16

def respond_to_missing?(name, *_)
  @options.has_key?(name)
end