Using Tuples in Ruby?

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

    You can do something similiar with destructuring:

    def something((a, b))
      a + b
    end
    
    p something([1, 2])
    

    This prints out 3 as expected.

提交回复
热议问题