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.
369 370 371 372 |
# File 'lib/primalize/single.rb', line 369 def initialize types, &coercion @types = types @coercion = coercion end |
Instance Method Details
#===(value) ⇒ Object
374 375 376 |
# File 'lib/primalize/single.rb', line 374 def === value value.nil? || @types.any? { |type| type === value } end |
#inspect ⇒ Object
378 379 380 |
# File 'lib/primalize/single.rb', line 378 def inspect "optional(#{@types.map(&:inspect).join(', ')})" end |