Class: Common::Descending

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/common/models/comparable/descending.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Descending

Returns a new instance of Descending.



10
11
12
# File 'lib/common/models/comparable/descending.rb', line 10

def initialize(obj)
  @obj = obj
end

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



8
9
10
# File 'lib/common/models/comparable/descending.rb', line 8

def obj
  @obj
end

Instance Method Details

#<=>(other) ⇒ Object

This will always force nil values to the end



15
16
17
18
19
20
21
# File 'lib/common/models/comparable/descending.rb', line 15

def <=>(other)
  return  0 if !obj && !other.obj
  return  1 unless obj
  return -1 unless other.obj

  -(obj <=> other.obj)
end