Class: Class

Inherits:
Object show all
Defined in:
lib/union_type/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#|(other) ⇒ UnionType

Returns a UnionType combining self and other. Enables the String | Integer literal syntax.

Examples:

String | Integer          # => UnionType(Integer | String)
String | Integer | Float  # => UnionType(Float | Integer | String)

Parameters:

Returns:

Raises:



12
13
14
15
16
17
18
19
20
21
# File 'lib/union_type/core_ext.rb', line 12

def |(other)
  case other
  when Class
    UnionType.new(self, other)
  when UnionType
    UnionType.new(self, *other)
  else
    raise TypeError, "expected Class or UnionType, got #{other.class}"
  end
end