Class: Parlour::Types::Union

Inherits:
Type
  • Object
show all
Defined in:
lib/parlour/types.rb

Overview

A type which is (at least) one of the wrapped types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#hash, #to_type, to_type

Constructor Details

#initialize(types) ⇒ Union

Returns a new instance of Union.



109
110
111
# File 'lib/parlour/types.rb', line 109

def initialize(types)
  @types = types.map(&method(:to_type))
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



119
120
121
# File 'lib/parlour/types.rb', line 119

def types
  @types
end

Instance Method Details

#==(other) ⇒ Object



114
115
116
# File 'lib/parlour/types.rb', line 114

def ==(other)
  Union === other && types == other.types
end

#describeObject



132
133
134
# File 'lib/parlour/types.rb', line 132

def describe
  "Union<#{types.map(&:describe).join(', ')}>"
end

#generate_rbiObject



122
123
124
# File 'lib/parlour/types.rb', line 122

def generate_rbi
  "T.any(#{types.map(&:generate_rbi).join(', ')})"
end

#generate_rbsObject



127
128
129
# File 'lib/parlour/types.rb', line 127

def generate_rbs
  "(#{types.map(&:generate_rbs).join(' | ')})"
end