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



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

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

Returns:

  • (Boolean)


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

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