Ruby – Using Tuples in Ruby


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 class in Python, where you can use . notation to find the value for which you are looking. I'm wanting this so that I can create an implementation of D, similar to Dee for Python.

Best Solution


Brief example:

require 'ostruct'

person =    = "John Smith"
person.age     = 70
person.pension = 300

puts     # -> "John Smith"
puts person.age      # -> 70
puts person.address  # -> nil