class Dry::Types::Option

Public Instance Methods

call_safe(input = Undefined) { |output| ... } click to toggle source

@param [Fear::Option, Object] input

@return [Fear::Option]

@api private

# File lib/dry/types/fear/option.rb, line 33
def call_safe(input = Undefined)
  case input
  when ::Fear::Option
    input
  when Undefined
    Fear.none
  else
    Fear.option(type.call_safe(input) { |output = input| return yield(output) })
  end
end
call_unsafe(input = Undefined) click to toggle source

@param [Fear::Option, Object] input

@return [Fear::Option]

@api private

# File lib/dry/types/fear/option.rb, line 17
def call_unsafe(input = Undefined)
  case input
  when ::Fear::Option
    input
  when Undefined
    Fear.none
  else
    Fear.option(type.call_unsafe(input))
  end
end
default(value) click to toggle source

@param [Object] value

@see Dry::Types::Builder#default

@raise [ArgumentError] if nil provided as default value

@api public

Calls superclass method
# File lib/dry/types/fear/option.rb, line 73
def default(value)
  if value.nil?
    raise ArgumentError, "nil cannot be used as a default of a maybe type"
  else
    super
  end
end
default?() click to toggle source

@return [true]

@api public

# File lib/dry/types/fear/option.rb, line 62
def default?
  true
end
try(input = Undefined) click to toggle source

@param [Object] input

@return [Result::Success]

@api public

# File lib/dry/types/fear/option.rb, line 49
def try(input = Undefined)
  result = type.try(input)

  if result.success?
    Result::Success.new(Fear.option(result.input))
  else
    result
  end
end