Class: Invert

Inherits:
Object
  • Object
show all
Defined in:
lib/invert.rb

Overview

Wrap an object to invert <=> method.

items.sort_by {|r| [r.prop1, Invert.new(r.prop2)]}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r) ⇒ Invert

Returns a new instance of Invert.



19
20
21
# File 'lib/invert.rb', line 19

def initialize(r)
  @r = r
end

Instance Attribute Details

#rObject (readonly)

Returns the value of attribute r.



17
18
19
# File 'lib/invert.rb', line 17

def r
  @r
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
# File 'lib/invert.rb', line 23

def <=>(other)
  -(@r <=> other.r)
end