module T
Public Class Methods
any(*typdefs)
click to toggle source
# File lib/emery/type.rb, line 164 def T.any(*typdefs) AnyType.new(*typdefs) end
array(item_type)
click to toggle source
# File lib/emery/type.rb, line 156 def T.array(item_type) ArrayType.new(item_type) end
check(type, value)
click to toggle source
# File lib/emery/type.rb, line 129 def T.check(type, value) if type.methods.include? :check type.check(value) else if type != NilClass T.check_not_nil(type, value) end if !value.is_a? type raise TypeError.new("Value '#{value.inspect.to_s}' type is #{value.class} - #{type} is required") end end return value end
check_not_nil(type, value)
click to toggle source
# File lib/emery/type.rb, line 2 def T.check_not_nil(type, value) if value == nil raise TypeError.new("Type #{type.to_s} does not allow nil value") end end
check_var(var_name, type, value)
click to toggle source
# File lib/emery/type.rb, line 172 def T.check_var(var_name, type, value) begin check(type, value) return value rescue TypeError => e raise TypeError.new("Variable #{var_name} type check failed, expected type: #{type.to_s}, value: #{value}") end end
hash(key_type, value_type)
click to toggle source
# File lib/emery/type.rb, line 160 def T.hash(key_type, value_type) HashType.new(key_type, value_type) end
instance_of?(type, value)
click to toggle source
# File lib/emery/type.rb, line 143 def T.instance_of?(type, value) begin T.check(type, value) true rescue TypeError false end end
nilable(value_type)
click to toggle source
# File lib/emery/type.rb, line 152 def T.nilable(value_type) Nilable.new(value_type) end
union(*cases)
click to toggle source
# File lib/emery/type.rb, line 168 def T.union(*cases) UnionType.new(*cases) end