I’ve started with Ruby and am finding new, shorter, elegant ways to write code everyday.
In solving Project Euler problems, I’ve written a lot of code like
if best_score < current_score
best_score = current_score
end
Is there a more elegant way to write this?
see: Enumerable.max
disclaimer: although this is a little more readable (imho), it’s less performant:
will result in (with ruby 1.8.6 (2008-08-11 patchlevel 287)):