Module: Algebrick::TypeCheck

Overview

noinspection RubyInstanceMethodNamingConvention

Instance Method Summary collapse

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

Returns:



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

Returns:



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?

Returns:



20
21
22
# File 'lib/algebrick/type_check.rb', line 20

def Type?(value, *types)
  types.any? { |t| value.is_a? t }
end