class Type::Definition::Nilable

Nilable Type::Definitions are the same as their non-nilable counterparts with the following exceptions:

Public Class Methods

new(parent) click to toggle source
Calls superclass method Type::Definition::new
# File lib/type/definition/nilable.rb, line 23
def initialize(parent)
  super(nil, parent)
end

Public Instance Methods

cast!(input) click to toggle source

Casts the input unless it is nil

Calls superclass method Type::Definition#cast!
# File lib/type/definition/nilable.rb, line 33
def cast!(input)
  return nil if input.nil?
  super
end
nilable() click to toggle source

@return [self]

# File lib/type/definition/nilable.rb, line 44
def nilable
  self
end
nilable?() click to toggle source

@return [True]

# File lib/type/definition/nilable.rb, line 39
def nilable?
  true
end
to_s() click to toggle source

@return [String]

Calls superclass method Type::Definition#to_s
# File lib/type/definition/nilable.rb, line 49
def to_s
  parent_name = @parent && @parent.name
  parent_name ? "Type::#{parent_name}(nilable)" : super
end
valid?(input, *args) click to toggle source

Returns true if input is nil or the input is valid

Calls superclass method Type::Definition#valid?
# File lib/type/definition/nilable.rb, line 28
def valid?(input, *args)
  input.nil? || super
end