Math.max or why is there no integer maximum function in ruby 2

Posted by chad on December 07, 2007

There is no Math.max function. Instead, use an array:

>> [2,3,4].max
=> 4

I would argue there should be, because it is not intuitively obvious that this type of integer comparison would live off of an array. One argument could be that the array approach allows for non-integer types to be compared, and that the increase in flexibility has an increase in obscurity as its side-effect…

>> ["chicken","fox"].max
=> "fox"

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. KenLee Fri, 28 Nov 2008 08:57:17 UTC

    Thanks Chad!
    Simple and effective, That’s the Ruby Way!

  2. Anibal Wed, 28 Oct 2009 07:02:09 UTC

    Gracias, me aclaró la duda

Comments