views:

71

answers:

2

Of course there are a thousand ways to get this done, but is the simplest (or most elegant) way to achieve this?

[4,8].max

That's actually not too shabby, but what would you do?

+1  A: 

That's exactly why Enumerable#max has been defined for any class which implements Comparable. It's definitely the simplest. To really understad what's happening, you'd need to look how it's been implemented in the core library of your favourite Ruby implementation (and it's probably optimised).

Tate Johnson
A: 

If you don't want to spawn an array, there's the conditional operator:

max = a > b ? a : b
FM