class RSchema::Schemas::Maybe
A schema representing that a value may be `nil`
If the value is not `nil`, it must conform to the subschema
@example A nil-able Integer
schema = RSchema.define{ maybe(_Integer) } schema.valid?(5) #=> true schema.valid?(nil) #=> true
Attributes
subschema[R]
Public Class Methods
new(subschema)
click to toggle source
# File lib/rschema/schemas/maybe.rb, line 18 def initialize(subschema) @subschema = subschema end
Public Instance Methods
call(value, options)
click to toggle source
# File lib/rschema/schemas/maybe.rb, line 22 def call(value, options) if value.nil? Result.success(value) else @subschema.call(value, options) end end
with_wrapped_subschemas(wrapper)
click to toggle source
# File lib/rschema/schemas/maybe.rb, line 30 def with_wrapped_subschemas(wrapper) self.class.new(wrapper.wrap(subschema)) end