Class: Strict::Return
- Inherits:
-
Object
- Object
- Strict::Return
- Defined in:
- lib/strict/return.rb
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#validator ⇒ Object
readonly
Returns the value of attribute validator.
Class Method Summary collapse
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(validator:, coercer:) ⇒ Return
constructor
A new instance of Return.
- #valid?(value) ⇒ Boolean
Constructor Details
#initialize(validator:, coercer:) ⇒ Return
Returns a new instance of Return.
13 14 15 16 |
# File 'lib/strict/return.rb', line 13 def initialize(validator:, coercer:) @validator = validator @coercer = coercer end |
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
11 12 13 |
# File 'lib/strict/return.rb', line 11 def coercer @coercer end |
#validator ⇒ Object (readonly)
Returns the value of attribute validator.
11 12 13 |
# File 'lib/strict/return.rb', line 11 def validator @validator end |
Class Method Details
.make(validator = Validators::Anything.instance, coerce: false) ⇒ Object
6 7 8 |
# File 'lib/strict/return.rb', line 6 def make(validator = Validators::Anything.instance, coerce: false) new(validator: validator, coercer: coerce) end |
Instance Method Details
#coerce(value) ⇒ Object
24 25 26 27 28 |
# File 'lib/strict/return.rb', line 24 def coerce(value) return value unless coercer coercer.call(value) end |
#valid?(value) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/strict/return.rb', line 18 def valid?(value) return true unless Strict.configuration.validate? validator === value end |