Class: Judges::Options
- Inherits:
-
Object
- Object
- Judges::Options
- Defined in:
- lib/judges/options.rb
Overview
Options for ruby scripts.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(pairs) ⇒ Options
constructor
Ctor.
-
#method_missing(*args) ⇒ Object
Get option by name.
-
#respond_to?(_method, _include_private = false) ⇒ Boolean
rubocop:disable Style/OptionalBooleanParameter.
- #respond_to_missing?(_method, _include_private = false) ⇒ Boolean
Constructor Details
#initialize(pairs) ⇒ Options
Ctor.
32 33 34 |
# File 'lib/judges/options.rb', line 32 def initialize(pairs) @pairs = pairs end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
Get option by name.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/judges/options.rb', line 37 def method_missing(*args) @hash ||= (if @pairs.nil? [] else (@pairs.is_a?(Hash) ? @pairs.map { |k, v| "#{k}=#{v}" } : @pairs) end).to_h do |pair| p = pair.split('=', 2) [p[0].to_sym, p[1].match?(/^[0-9]+$/) ? p[1].to_i : p[1]] end k = args[0].downcase @hash[k] end |
Instance Method Details
#respond_to?(_method, _include_private = false) ⇒ Boolean
rubocop:disable Style/OptionalBooleanParameter
51 52 53 54 |
# File 'lib/judges/options.rb', line 51 def respond_to?(_method, _include_private = false) # rubocop:enable Style/OptionalBooleanParameter true end |
#respond_to_missing?(_method, _include_private = false) ⇒ Boolean
56 57 58 |
# File 'lib/judges/options.rb', line 56 def respond_to_missing?(_method, _include_private = false) true end |