Tuple

A Tuple is typically created with a tuple literal:

  1. tuple = {1, "hello", 'x'} # Tuple(Int32, String, Char)
  2. tuple[0] #=> 1 (Int32)
  3. tuple[1] #=> "hello" (String)
  4. tuple[2] #=> 'x' (Char)

To create an empty tuple use Tuple.new.

To denote a tuple type you can write:

  1. # The type denoting a tuple of Int32, String and Char
  2. Tuple(Int32, String, Char)

In type restrictions, generic type arguments and other places where a type is expected, you can use a shorter syntax, as explained in the type grammar:

  1. # An array of tuples of Int32, String and Char
  2. Array({Int32, String, Char})