Return two and more values from a method

前端 未结 4 483
北海茫月
北海茫月 2020-12-23 12:45

Is there any possibility to return multiple values from method? Something like this:

def someMethod()
  return [\"a\", 10, SomeObject.new]
end

[a, b, c] =         


        
4条回答
  •  情书的邮戳
    2020-12-23 13:34

    You can achieve this returning an array too, like

    def sumdiff(x, y)
        [x+y, x-y]
    end
    

    which seems functionally equivalent to

    def sumdiff(x, y)
        return x+y, x-y
    end
    

提交回复
热议问题