How to find a min/max with Ruby

后端 未结 6 2236
长情又很酷
长情又很酷 2020-12-04 05:29

I want to use min(5,10), or Math.max(4,7). Are there functions to this effect in Ruby?

6条回答
  •  孤街浪徒
    2020-12-04 06:02

    All those results generate garbage in a zealous attempt to handle more than two arguments. I'd be curious to see how they perform compared to good 'ol:

    def max (a,b)
      a>b ? a : b
    end
    

    which is, by-the-way, my official answer to your question.

提交回复
热议问题