Class: TypeStruct::Union

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/type_struct/ext.rb,
lib/type_struct/union.rb

Defined Under Namespace

Modules: Ext

Instance Method Summary collapse

Constructor Details

#initialize(*classes) ⇒ Union

Returns a new instance of Union.



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

def initialize(*classes)
  @classes = classes
end

Instance Method Details

#===(other) ⇒ Object



23
24
25
# File 'lib/type_struct/union.rb', line 23

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

#each(*args, &block) ⇒ Object



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

def each(*args, &block)
  @classes.each(*args, &block)
end

#to_sObject Also known as: inspect



33
34
35
# File 'lib/type_struct/ext.rb', line 33

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

#|(other) ⇒ Object



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

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