Class: ActiveMapper::Adapter::Memory::Order::Attribute
- Inherits:
-
Object
- Object
- ActiveMapper::Adapter::Memory::Order::Attribute
- Defined in:
- lib/active_mapper/adapter/memory/order/attribute.rb
Instance Method Summary collapse
- #-@ ⇒ Object
-
#initialize(name) ⇒ Attribute
constructor
A new instance of Attribute.
- #reverse ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(name) ⇒ Attribute
Returns a new instance of Attribute.
6 7 8 9 |
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 6 def initialize(name) @name = name @direction = :asc end |
Instance Method Details
#-@ ⇒ Object
11 12 13 14 |
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 11 def -@ @direction = :desc self end |
#reverse ⇒ Object
16 17 18 19 |
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 16 def reverse @direction = asc? ? :desc : :asc self end |
#to_proc ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/active_mapper/adapter/memory/order/attribute.rb', line 21 def to_proc proc do |x,y| if asc? x.send(@name) <=> y.send(@name) else y.send(@name) <=> x.send(@name) end end end |