Class: Listen::Options
- Inherits:
-
Object
- Object
- Listen::Options
- Defined in:
- lib/listen/options.rb
Instance Method Summary collapse
-
#initialize(opts, defaults) ⇒ Options
constructor
A new instance of Options.
- #method_missing(name, *_) ⇒ Object
-
#respond_to_missing?(name, *_) ⇒ Boolean
rubocop:disable Lint/MissingSuper.
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 = {} = opts.dup defaults.each_key do |key| @options[key] = .delete(key) || defaults[key] end .empty? or raise ArgumentError, "Unknown 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
16 17 18 |
# File 'lib/listen/options.rb', line 16 def respond_to_missing?(name, *_) @options.has_key?(name) end |