Module: Functional::TypeCheck
- Defined in:
- lib/functional/type_check.rb
Overview
Supplies type-checking helpers whenever included.
Class Method Summary (collapse)
-
+ (Class) Child!(value, *types)
Is the given class a subclass or exact match of one or more of the modules and/or classes in the given list?.
-
+ (Boolean) Child?(value, *types)
Is the given class a subclass or exact match of one or more of the modules and/or classes in the given list?.
-
+ (Object) Match!(value, *types)
Is the given value object is an instance of or descendant of one of the classes/modules in the given list? Raises an exception on failure.
-
+ (Boolean) Match?(value, *types)
Is the given value object is an instance of or descendant of one of the classes/modules in the given list?.
-
+ (Object) Type!(value, *types)
Performs an
is_a?
check of the given value object against the given list of modules and/or classes. -
+ (Boolean) Type?(value, *types)
Performs an
is_a?
check of the given value object against the given list of modules and/or classes.
Class Method Details
+ (Class) Child!(value, *types)
Is the given class a subclass or exact match of one or more of the modules and/or classes in the given list?
90 91 92 93 94 |
# File 'lib/functional/type_check.rb', line 90 def Child!(value, *types) Child?(value, *types) or TypeCheck.error(value, 'is not child', types) value end |
+ (Boolean) Child?(value, *types)
Is the given class a subclass or exact match of one or more of the modules and/or classes in the given list?
76 77 78 79 |
# File 'lib/functional/type_check.rb', line 76 def Child?(value, *types) Type?(value, Class) && types.any? { |t| value <= t } end |
+ (Object) Match!(value, *types)
Is the given value object is an instance of or descendant of one of the classes/modules in the given list? Raises an exception on failure.
Performs the check using the ===
operator.
62 63 64 65 66 |
# File 'lib/functional/type_check.rb', line 62 def Match!(value, *types) Match?(value, *types) or TypeCheck.error(value, 'is not matching', types) value end |
+ (Boolean) Match?(value, *types)
Is the given value object is an instance of or descendant of one of the classes/modules in the given list?
Performs the check using the ===
operator.
45 46 47 |
# File 'lib/functional/type_check.rb', line 45 def Match?(value, *types) types.any? { |t| t === value } end |
+ (Object) Type!(value, *types)
Performs an is_a?
check of the given value object against the
given list of modules and/or classes. Raises an exception on failure.
29 30 31 32 33 |
# File 'lib/functional/type_check.rb', line 29 def Type!(value, *types) Type?(value, *types) or TypeCheck.error(value, 'is not', types) value end |
+ (Boolean) Type?(value, *types)
Performs an is_a?
check of the given value object against the
given list of modules and/or classes.
15 16 17 |
# File 'lib/functional/type_check.rb', line 15 def Type?(value, *types) types.any? { |t| value.is_a? t } end |