Using Tuples in Ruby?

后端 未结 7 1041
醉话见心
醉话见心 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
    

提交回复
热议问题