Class: Compendium::Option
- Inherits:
-
Object
- Object
- Compendium::Option
- Defined in:
- lib/compendium/option.rb
Instance Attribute Summary collapse
-
#choices ⇒ Object
Returns the value of attribute choices.
-
#default ⇒ Object
Returns the value of attribute default.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Option
constructor
A new instance of Option.
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(hash = {}) ⇒ Option
Returns a new instance of Option.
13 14 15 16 17 18 19 20 21 |
# File 'lib/compendium/option.rb', line 13 def initialize(hash = {}) raise ArgumentError, "name must be provided" unless hash.key?(:name) @name = hash.delete(:name).to_sym @default = hash.delete(:default) @choices = hash.delete(:choices) self.type = hash.delete(:type) @options = hash.with_indifferent_access end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
27 28 29 30 31 |
# File 'lib/compendium/option.rb', line 27 def method_missing(name, *args, &block) return [name] if .key?(name) return .key?(name[0...-1]) if name.to_s.end_with?('?') super end |
Instance Attribute Details
#choices ⇒ Object
Returns the value of attribute choices.
8 9 10 |
# File 'lib/compendium/option.rb', line 8 def choices @choices end |
#default ⇒ Object
Returns the value of attribute default.
8 9 10 |
# File 'lib/compendium/option.rb', line 8 def default @default end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/compendium/option.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/compendium/option.rb', line 8 def @options end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/compendium/option.rb', line 8 def type @type end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
33 34 35 36 |
# File 'lib/compendium/option.rb', line 33 def respond_to_missing?(name, include_private = false) return true if .key?(name) super end |