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.



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

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.



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

def arguments
  @arguments
end

#definitionObject (readonly)

Returns the value of attribute definition.



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

def definition
  @definition
end

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

Instance Method Details

#childrenObject



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

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

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

Returns:

  • (Boolean)


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

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

#to_sObject



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

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