that the values array had this method of course…
Just in case you didn’t realise this, the Array class (and, thus, all
arrays) has the max method. If you wanted the max of two values, you’d
put
those two values in an array and then take the max of that array…
a = 2
b = 3
max = [a, b].max
Since Hash#values returns an _array_ of hash values...
Just in case you didn’t realise this, the Array class (and, thus, all
arrays) has the max method. If you wanted the max of two values, you’d
put those two values in an array and then take the max of that array…
a = 2
b = 3
max = [a, b].max
Since Hash#values returns an array of hash values…
I did realize that the Array class has the max method. After some
browsing
to the documentation I also understand the inclusion of Enumerable and
its
effects. I must say, my code gets really clean this way.
I’m starting to like ruby a lot. Yesterday I had to prototype an
algorithm
and with Ruby I did that in a quarter of an hour. That’s really fast! My
colleagues were surprised about the code, they knew how to read it
without
knowing ruby!
As the thread is about hashes, it’s nice to know that the #max method,
when applied to hashes, apparently yields the maximum value for the
keys, not for the values.
This is really sweet, but I think in this context it’s worth noting
that:
{‘a’ => 1, ‘b’ => 10, ‘z’ => 5}.max #=> [“z”, 5]
As the thread is about hashes, it’s nice to know that the #max method,
when applied to hashes, apparently yields the maximum value for the
keys, not for the values.