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"
Math.max or why is there no integer maximum function in ruby 3
Posted by chad
on December 07, 2007
Trackbacks
Use this link to trackback from your own site.
Thanks Chad!
Simple and effective, That’s the Ruby Way!
Gracias, me aclaró la duda
> because it is not intuitively obvious that this type of integer comparison would live off of an array
The bigger problem is that it’s absurdly inefficient to create an array simply to compare two numbers. That Ruby’s author doesn’t appear to care is probably why Ruby is so slow.