Class: MilkTea::Types::VariantInstance

Inherits:
Variant show all
Defined in:
lib/milk_tea/core/types/types.rb

Instance Attribute Summary collapse

Attributes inherited from Variant

#module_name, #name

Instance Method Summary collapse

Methods inherited from Variant

#arm, #arm_names, #define_arms, #has_payload?

Methods inherited from Base

#accept, #bitwise?, #boolean?, #field_c_name, #float?, #integer?, #numeric?, #sendable?, #void?

Constructor Details

#initialize(definition, arguments) ⇒ VariantInstance

Returns a new instance of VariantInstance.



1151
1152
1153
1154
1155
1156
# File 'lib/milk_tea/core/types/types.rb', line 1151

def initialize(definition, arguments)
  super(definition.name, module_name: definition.module_name)
  @definition = definition
  @arguments = arguments.freeze
  @hash = [self.class, definition, @arguments].hash
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



1149
1150
1151
# File 'lib/milk_tea/core/types/types.rb', line 1149

def arguments
  @arguments
end

#definitionObject (readonly)

Returns the value of attribute definition.



1149
1150
1151
# File 'lib/milk_tea/core/types/types.rb', line 1149

def definition
  @definition
end

#hashObject (readonly)

Returns the value of attribute hash.



1164
1165
1166
# File 'lib/milk_tea/core/types/types.rb', line 1164

def hash
  @hash
end

Instance Method Details

#childrenObject



1171
1172
1173
# File 'lib/milk_tea/core/types/types.rb', line 1171

def children
  arm_names.flat_map { |a| arm(a).values }
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


1158
1159
1160
# File 'lib/milk_tea/core/types/types.rb', line 1158

def eql?(other)
  other.is_a?(VariantInstance) && other.definition == definition && other.arguments == arguments
end

#to_sObject



1166
1167
1168
1169
# File 'lib/milk_tea/core/types/types.rb', line 1166

def to_s
  base = module_name ? "#{module_name}.#{name}" : name
  "#{base}[#{arguments.join(', ')}]"
end