Class: EasyTalk::Types::Tuple
- Inherits:
-
Object
- Object
- EasyTalk::Types::Tuple
- Extended by:
- T::Sig
- Defined in:
- lib/easy_talk/types/tuple.rb
Overview
Represents a tuple type for arrays with positional type validation.
A tuple is an array where each position has a specific type. This class stores the types for each position.
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#initialize(*types) ⇒ Tuple
constructor
A new instance of Tuple.
- #name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*types) ⇒ Tuple
Returns a new instance of Tuple.
28 29 30 31 32 33 |
# File 'lib/easy_talk/types/tuple.rb', line 28 def initialize(*types) raise ArgumentError, 'Tuple requires at least one type' if types.empty? raise ArgumentError, 'Tuple types cannot be nil' if types.any?(&:nil?) @types = types.freeze end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
21 22 23 |
# File 'lib/easy_talk/types/tuple.rb', line 21 def types @types end |
Instance Method Details
#name ⇒ Object
48 49 50 |
# File 'lib/easy_talk/types/tuple.rb', line 48 def name to_s end |
#to_s ⇒ Object
39 40 41 42 |
# File 'lib/easy_talk/types/tuple.rb', line 39 def to_s type_names = @types.map { |t| (t.respond_to?(:name) && t.name) || t.to_s } "T::Tuple[#{type_names.join(', ')}]" end |