Does anyone use tuples in Ruby? If so, how may one implement a tuple? Ruby hashes are nice and work almost as well, but I\'d really like to see something like the Tuple clas
I'm the author of Gem for Ruby tuples.
You are provided with two classes:
Tuple in generalPair in particularYou can initialize them in different ways:
Tuple.new(1, 2)
Tuple.new([1, 2])
Tuple(1, 2)
Tuple([1, 2])
Tuple[1, 2]
Both of the classes have some auxiliary methods:
length / arity - which returns number of values inside tuplefirst / last / second (only pair) - which returns a corresponding elements[] that gives you an access to a particular elements