Class: Sinclair::Options
- Inherits:
-
Object
- Object
- Sinclair::Options
- Defined in:
- lib/sinclair/options.rb,
lib/sinclair/options/builder.rb
Overview
Base options class
Defined Under Namespace
Classes: Builder
Class Method Summary collapse
-
.allow(name) ⇒ Set<Symbol>
private
Allow new option.
-
.allowed_options ⇒ Set<Symbol>
private
Options allowed when initializing options.
-
.invalid_options_in(names) ⇒ Array<Symbol>
private
returns invalid options.
-
.with_options(*options) ⇒ Array<MethodDefinition>
Add available options.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
returns if other equals to self.
-
#initialize(options = {}) ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize(options = {}) ⇒ Options
Returns a new instance of Options.
84 85 86 87 88 89 90 |
# File 'lib/sinclair/options.rb', line 84 def initialize( = {}) () .each do |key, value| instance_variable_set("@#{key}", value) end end |
Class Method Details
.allow(name) ⇒ Set<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allow new option
This does not create the method
44 45 46 |
# File 'lib/sinclair/options.rb', line 44 def allow(name) << name.to_sym end |
.allowed_options ⇒ Set<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Options allowed when initializing options
54 55 56 |
# File 'lib/sinclair/options.rb', line 54 def @allowed_options ||= superclass.try(:allowed_options).dup || Set.new end |
.invalid_options_in(names) ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
returns invalid options
31 32 33 |
# File 'lib/sinclair/options.rb', line 31 def (names) names.map(&:to_sym) - .to_a end |
.with_options(*options) ⇒ Array<MethodDefinition> .with_options(*options, **defaults) ⇒ Array<MethodDefinition>
Add available options
77 78 79 |
# File 'lib/sinclair/options.rb', line 77 def (*) Builder.new(self, *).build end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
returns if other equals to self
97 98 99 100 101 102 103 |
# File 'lib/sinclair/options.rb', line 97 def ==(other) return false unless self.class == other.class self.class..all? do |name| public_send(name) == other.public_send(name) end end |