Class: Primalize::Single::Optional
- Inherits:
-
Object
- Object
- Primalize::Single::Optional
- Includes:
- Type
- Defined in:
- lib/primalize/single.rb
Constant Summary
Constants included from Type
Instance Method Summary collapse
- #===(value) ⇒ Object
-
#initialize(types, &coercion) ⇒ Optional
constructor
A new instance of Optional.
- #inspect ⇒ Object
Methods included from Type
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 |
#inspect ⇒ Object
362 363 364 |
# File 'lib/primalize/single.rb', line 362 def inspect "optional(#{@types.map(&:inspect).join(', ')})" end |