Using Tuples in Ruby?

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

    While this isn't strictly a tuple (can't do dot notation of members), you can assign a list of variables from a list, which often will solve issues with ruby being pass-by-value when you are after a list of return values.

    E.g.

    :linenum > (a,b,c) = [1,2,3]
    :linenum > a
      => 1
    :linenum > b
      => 2
    :linenum > c
      => 3
    

提交回复
热议问题