Class: Tapioca::Compilers::DryStruct::DryAstCompiler::Sum
- Inherits:
-
Object
- Object
- Tapioca::Compilers::DryStruct::DryAstCompiler::Sum
- Defined in:
- lib/tapioca/dsl/compilers/dry_struct.rb
Overview
Represents dry’s sum type
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #delete_nilclass! ⇒ Object
- #first ⇒ Object
- #include_nilclass? ⇒ Boolean
- #include_undefined? ⇒ Boolean
-
#initialize ⇒ Sum
constructor
A new instance of Sum.
- #inspect ⇒ Object
- #map(&block) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Sum
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
#types ⇒ Object (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 |
#first ⇒ Object
82 83 84 |
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 82 def first @types.first end |
#include_nilclass? ⇒ Boolean
90 91 92 |
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 90 def include_nilclass? @types.include?(::NilClass) end |
#include_undefined? ⇒ 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 |
#inspect ⇒ Object
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 |
#size ⇒ Object
66 67 68 |
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 66 def size @types.size end |
#to_s ⇒ Object
98 99 100 |
# File 'lib/tapioca/dsl/compilers/dry_struct.rb', line 98 def to_s "Sum(#{@types.map(&:to_s).join(',')})" end |