Class: Primalize::Single::Optional

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/primalize/single.rb

Constant Summary

Constants included from Type

Type::DEFAULT_COERCION

Instance Method Summary collapse

Methods included from Type

#coerce

Constructor Details

#initialize(types, &coercion) ⇒ Optional

Returns a new instance of Optional.



353
354
355
356
# File 'lib/primalize/single.rb', line 353

def initialize types, &coercion
  @types = types
  @coercion = coercion
end

Instance Method Details

#===(value) ⇒ Object



358
359
360
# File 'lib/primalize/single.rb', line 358

def === value
  value.nil? || @types.any? { |type| type === value }
end

#inspectObject



362
363
364
# File 'lib/primalize/single.rb', line 362

def inspect
  "optional(#{@types.map(&:inspect).join(', ')})"
end