Class: TypeStruct::Union

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/type_struct/union.rb

Instance Method Summary collapse

Constructor Details

#initialize(*classes) ⇒ Union

Returns a new instance of Union.



8
9
10
# File 'lib/type_struct/union.rb', line 8

def initialize(*classes)
  @classes = classes
end

Instance Method Details

#===(other) ⇒ Object



16
17
18
# File 'lib/type_struct/union.rb', line 16

def ===(other)
  @classes.any? { |c| c === other }
end

#to_sObject Also known as: inspect



20
21
22
# File 'lib/type_struct/union.rb', line 20

def to_s
  "#<#{self.class} #{@classes.join('|')}>"
end

#|(other) ⇒ Object



12
13
14
# File 'lib/type_struct/union.rb', line 12

def |(other)
  Union.new(*@classes, other)
end