Class: Dialekt::RubyTypeChecker
- Inherits:
-
BasicTypeChecker
- Object
- BasicTypeChecker
- Dialekt::RubyTypeChecker
- Includes:
- Singleton
- Defined in:
- lib/dialekt/ruby_type_checker.rb
Overview
Ruby type checker
Instance Method Summary collapse
Methods inherited from BasicTypeChecker
Instance Method Details
#union_type(types:) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/dialekt/ruby_type_checker.rb', line 10 def union_type(types:) union_type = Set.new(types.flatten.uniq) raise ArgumentError, "Types must not be empty" if union_type.empty? union_type.size == 1 ? union_type.first : union_type end |
#valid?(type:, value:) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dialekt/ruby_type_checker.rb', line 18 def valid?(type:, value:) case type when Array, Set type.any? { |t| valid?(type: t, value: value) } when Class value.is_a?(type) else raise TypeError, "Illegal type '#{type}'" end end |