Module: Sortable::ClassMethods
- Defined in:
- lib/sortable.rb
Instance Method Summary collapse
Instance Method Details
#sortable(*sorters) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sortable.rb', line 9 def sortable(*sorters) define_method :"<=>", lambda { |other| comp = 0 sorters.each do |sorter| comp = if sorter.respond_to?(:call) sorter.call(self) <=> sorter.call(other) else self.send(sorter) <=> other.send(sorter) end break if comp != 0 end comp } end |