I usually do something like
array.sort{|a,b| a.something <=> b.something}
How should I DRY this up?
use sort_by
array.sort_by{|e| e.something}
or
sort_lambda = lambda{|e| e.something}
array.sort_by(&sort_lambda)
With latter you can reuse sort_lambda in other sort_by statements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With