Class: Strict::Return

Inherits:
Object
  • Object
show all
Defined in:
lib/strict/return.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#coercerObject (readonly)

Returns the value of attribute coercer.



11
12
13
# File 'lib/strict/return.rb', line 11

def coercer
  @coercer
end

#validatorObject (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

Returns:

  • (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