Class: Tapioca::Compilers::DryStruct::DryAstCompiler::Sum

Inherits:
Object
  • Object
show all
Defined in:
lib/tapioca/dsl/compilers/dry_struct.rb

Overview

Represents dry’s sum type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSum

Returns a new instance of Sum.



62
63
64
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 62

def initialize
  @types = ::Set.new
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



60
61
62
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 60

def types
  @types
end

Instance Method Details

#<<(arg) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 70

def <<(arg)
  if arg.is_a?(Sum)
    arg.types.each { |t| @types << t }
  else
    @types << arg
  end
end

#delete_nilclass!Object



94
95
96
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 94

def delete_nilclass!
  @types.reject! { |t| t == ::NilClass }
end

#firstObject



82
83
84
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 82

def first
  @types.first
end

#include_nilclass?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 90

def include_nilclass?
  @types.include?(::NilClass)
end

#include_undefined?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 86

def include_undefined?
  @types.any? { |t| t.is_a?(Undefined) }
end

#inspectObject



102
103
104
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 102

def inspect
  to_s
end

#map(&block) ⇒ Object



78
79
80
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 78

def map(&block)
  @types.map(&block)
end

#sizeObject



66
67
68
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 66

def size
  @types.size
end

#to_sObject



98
99
100
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 98

def to_s
  "Sum(#{@types.map(&:to_s).join(',')})"
end