Class: RequestType::Validator::ArrayWithDefault
- Inherits:
-
Object
- Object
- RequestType::Validator::ArrayWithDefault
- Defined in:
- app/models/request_type/validator.rb
Overview
Array class that lets you set a default value If first argument is an array, second argument is assumed to be default Raises exception is default is not in the array In all other cases passes argument to standard array initializer
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
Instance Method Summary collapse
-
#initialize(array, default) ⇒ ArrayWithDefault
constructor
A new instance of ArrayWithDefault.
- #method_missing(method) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(array, default) ⇒ ArrayWithDefault
Returns a new instance of ArrayWithDefault.
71 72 73 74 75 76 |
# File 'app/models/request_type/validator.rb', line 71 def initialize(array, default) raise StandardError, 'Default is not in array' unless array.include?(default) @default = default @array = array end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
78 79 80 |
# File 'app/models/request_type/validator.rb', line 78 def method_missing(method, ...) @array.send(method, ...) end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
69 70 71 |
# File 'app/models/request_type/validator.rb', line 69 def default @default end |
Instance Method Details
#to_a ⇒ Object
84 85 86 |
# File 'app/models/request_type/validator.rb', line 84 def to_a @array end |