Using Tuples in Ruby?

后端 未结 7 986
醉话见心
醉话见心 2020-12-24 00:24

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

相关标签:
7条回答
  • 2020-12-24 01:09

    Based on the fact that you talk about hashes and . notation I'm going to assume you mean a different kind of tuple than the (1. "a") sort. You're probably looking for the Struct class. eg:

    Person = Struct.new(:name, :age)
    me = Person.new
    me.name = "Guy"
    me.age =  30
    
    0 讨论(0)
提交回复
热议问题