Class: RBS::Dynamic::Builder::Types
- Inherits:
-
Object
- Object
- RBS::Dynamic::Builder::Types
show all
- Defined in:
- lib/rbs/dynamic/builder/types.rb
Defined Under Namespace
Modules: RBSTypeMerger, ToRBSType
Constant Summary
collapse
- BOOL =
RBS::Types::Bases::Bool.new(location: nil)
- VOID =
RBS::Types::Bases::Void.new(location: nil)
- ANY =
RBS::Types::Bases::Any.new(location: nil)
- NILCLASS_RBS_TYPE =
NilClass.to_rbs_type
- NIL_RBS_TYPE =
nil.to_rbs_type
- TRUECLASS_RBS_TYPE =
TrueClass.to_rbs_type
- TRUE_RBS_TYPE =
true.to_rbs_type
- FALSECLASS_RBS_TYPE =
FalseClass.to_rbs_type
- FALSE_RBS_TYPE =
false.to_rbs_type
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(type) ⇒ Types
Returns a new instance of Types.
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/rbs/dynamic/builder/types.rb', line 149
def initialize(type)
@types = case type
when nil
[nil]
when Hash
[type]
else
Array(type)
end.map(&:to_rbs_type).uniq.zip_type
end
|
Instance Attribute Details
#types ⇒ Object
Returns the value of attribute types.
147
148
149
|
# File 'lib/rbs/dynamic/builder/types.rb', line 147
def types
@types
end
|
Instance Method Details
#build ⇒ Object
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/rbs/dynamic/builder/types.rb', line 160
def build
if optional?
RBS::Types::Optional.new(
type: (target_types - [NIL_RBS_TYPE, NILCLASS_RBS_TYPE]).union_type,
location: nil
)
else
target_types.union_type
end
end
|
#optional? ⇒ Boolean
180
181
182
|
# File 'lib/rbs/dynamic/builder/types.rb', line 180
def optional?
!!types.group_by { _1 == NIL_RBS_TYPE || _1 == NILCLASS_RBS_TYPE }.values.then { |opt, other| opt&.size&.>=(1) && other&.size&.>=(1) }
end
|