Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Introcuce Literal::UnionType#resolve

This lets you look up which type in the union matched the value.

+17
+17
lib/literal/types/union_type.rb
··· 48 48 false 49 49 end 50 50 51 + def resolve(value) 52 + if @primitives.include?(value) 53 + value 54 + else 55 + types = @types 56 + 57 + i, len = 0, types.size 58 + while i < len 59 + type = types[i] 60 + return type if type === value 61 + i += 1 62 + end 63 + 64 + raise Literal::ArgumentError.new("No match found for #{value.inspect} in #{inspect}.") 65 + end 66 + end 67 + 51 68 def each(&) 52 69 if block_given? 53 70 @primitives.each(&)