Class: Kind::UnionType

Inherits:
Object
  • Object
show all
Includes:
BasicObject
Defined in:
lib/kind/objects/union_type.rb

Defined Under Namespace

Modules: Buildable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BasicObject

#[], #or, #or_nil, #or_null, #or_undefined, #value, #value?

Constructor Details

#initialize(kind) ⇒ UnionType

Returns a new instance of UnionType.



13
14
15
16
# File 'lib/kind/objects/union_type.rb', line 13

def initialize(kind)
  @kinds = Array(kind)
  @inspect = "(#{@kinds.map(&:name).join(' | ')})"
end

Instance Attribute Details

#inspectObject (readonly) Also known as: name

Returns the value of attribute inspect.



11
12
13
# File 'lib/kind/objects/union_type.rb', line 11

def inspect
  @inspect
end

Instance Method Details

#===(value) ⇒ Object



22
23
24
# File 'lib/kind/objects/union_type.rb', line 22

def ===(value)
  @kinds.any? { |kind| kind === value }
end

#|(kind) ⇒ Object



18
19
20
# File 'lib/kind/objects/union_type.rb', line 18

def |(kind)
  self.class.new(@kinds + [Interface[kind.nil? ? Kind::Nil : kind]])
end