Class: MilkTea::Types::VariantInstance

Inherits:
Variant show all
Defined in:
lib/milk_tea/core/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.



1140
1141
1142
1143
1144
1145
# File 'lib/milk_tea/core/types.rb', line 1140

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.



1138
1139
1140
# File 'lib/milk_tea/core/types.rb', line 1138

def arguments
  @arguments
end

#definitionObject (readonly)

Returns the value of attribute definition.



1138
1139
1140
# File 'lib/milk_tea/core/types.rb', line 1138

def definition
  @definition
end

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

Instance Method Details

#childrenObject



1160
1161
1162
# File 'lib/milk_tea/core/types.rb', line 1160

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

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

Returns:

  • (Boolean)


1147
1148
1149
# File 'lib/milk_tea/core/types.rb', line 1147

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

#to_sObject



1155
1156
1157
1158
# File 'lib/milk_tea/core/types.rb', line 1155

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