Tuple

Tuple is essentially an Array, but Comaparable and Immutable.

A tuple can be made using new or #[] just as one builds an array, or using the to_t method on a string or array. With a string tuple remembers the first non-alphanumeric character as the tuple divider.

Usage

  t1 = Tuple[1,2,3]
  t2 = Tuple[2,3,4]

  t1 < t2   #=> true
  t1 > t2   #=> false

  t1 = '1.2.3'.to_t
  t2 = '1-2-3'.to_t

  puts t1  #=> 1.2.3
  puts t2  #=> 1-2-3

  t1 == t2  #=> true

Keep in mind that Tuple[1,2,3] is not the same as Tuple[‘1’,’2’,’3’].

Todo

  • The hash method needs a touch-up.
  • There are a few more methods yet to borrow from Array. Consider how #+, #-, etc. ought to work.

Author

  • Thomas Sawyer

Copying

Copyright (c) 2005 Thomas Sawyer

Ruby License

This module is free software. You may use, modify, and/or redistribute this software under the same terms as Ruby.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Required Files