Module: Algebrick::TypeCheck
- Included in:
- DSL::TypeDefinitionScope, Matchers::Abstract, ParametrizedType, ProductConstructors::Abstract, Serializer, Type, Value
- Defined in:
- lib/algebrick/type_check.rb
Overview
noinspection RubyInstanceMethodNamingConvention
Instance Method Summary collapse
- #Child!(value, *types) ⇒ Object
- #Child?(value, *types) ⇒ Boolean
- #Match!(value, *types) ⇒ Object
- #Match?(value, *types) ⇒ Boolean
- #Type!(value, *types) ⇒ Object
-
#Type?(value, *types) ⇒ Boolean
FIND: type checking of collections?.
Instance Method Details
#Child!(value, *types) ⇒ Object
45 46 47 48 49 |
# File 'lib/algebrick/type_check.rb', line 45 def Child!(value, *types) Child?(value, *types) or TypeCheck.error(value, 'is not child', types) value end |
#Child?(value, *types) ⇒ Boolean
40 41 42 43 |
# File 'lib/algebrick/type_check.rb', line 40 def Child?(value, *types) Type?(value, Class) && types.any? { |t| value <= t } end |
#Match!(value, *types) ⇒ Object
34 35 36 37 38 |
# File 'lib/algebrick/type_check.rb', line 34 def Match!(value, *types) Match?(value, *types) or TypeCheck.error(value, 'is not matching', types) value end |
#Match?(value, *types) ⇒ Boolean
30 31 32 |
# File 'lib/algebrick/type_check.rb', line 30 def Match?(value, *types) types.any? { |t| t === value } end |
#Type!(value, *types) ⇒ Object
24 25 26 27 28 |
# File 'lib/algebrick/type_check.rb', line 24 def Type!(value, *types) Type?(value, *types) or TypeCheck.error(value, 'is not', types) value end |
#Type?(value, *types) ⇒ Boolean
FIND: type checking of collections?
20 21 22 |
# File 'lib/algebrick/type_check.rb', line 20 def Type?(value, *types) types.any? { |t| value.is_a? t } end |