Class: SyntaxTree::Reflection::Type::TupleType

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/reflection.rb

Overview

Represents a tuple type that holds a number of types in order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ TupleType

Returns a new instance of TupleType.



34
35
36
# File 'lib/syntax_tree/reflection.rb', line 34

def initialize(types)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



32
33
34
# File 'lib/syntax_tree/reflection.rb', line 32

def types
  @types
end

Instance Method Details

#===(value) ⇒ Object



38
39
40
41
# File 'lib/syntax_tree/reflection.rb', line 38

def ===(value)
  value.is_a?(Array) && value.length == types.length &&
    value.zip(types).all? { |item, type| type === item }
end

#inspectObject



43
44
45
# File 'lib/syntax_tree/reflection.rb', line 43

def inspect
  "[#{types.map(&:inspect).join(", ")}]"
end