Where’s Math.min and Math.max in Ruby?
Maybe it’s just me and I don’t know where to look, but this isn’t something I’m interested in spending 30 minutes looking for.
module Math
def self.max(a, b)
a > b ? a : b
end
def self.min(a, b)
a < b ? a : b
end
end
4 comments.
but this wouldn’t be very object-oriented
take a look at Enumerable#min, Enumerable#max
Thanks for the tip!
This means that I would have to create an array first.
[1, 10].max
To me this seems a lot less object oriented than having static methods. Creating a third object to compare two values seems quite a bit of an overkill and quite inefficient.
I was also wondering where the hell it was
Thanks.
Nice blog too !
Thanks!
I hope these functions will make it to the official version of module Math some day…
Leave a Reply