Should we have min and max routines somewhere in the core Ruby (additionally
to the ones defined in Enumerable)?
First I consider to add it to Numeric, but then I wrote something like
module Kernel
def min(a, b)
if a < b
a
else
b
end
end
end
Actually I can't say min(a,b) is much more beautiful compared to [a,b].min()
but at least you don't have to know anything about arrays when using it and
I expect it to be faster.
Maybe the implementation should include the block version allowing c =
min(a,b){|a,b| a.foo() < b.bar()}.
Well, there's at least one point to consider with the Kernel version. Kernel
is maybe not the right place for min since not all classes have meaningful
comparisons. So maybe Comparable is the place (or maybe not).
OTOH, maybe there should be min for the files too (making comparison by
default by file size or by string comparison of the contents of the file).
- Aleksi