Class: InstanceVariableComparability

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/availability/instance_variable_comparability.rb

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/availability/instance_variable_comparability.rb', line 3

def <=>(other)
  return 1 if other.nil?
  comparisons = comparability_ivar_names.map do |ivar|
    instance_variable_get(ivar) <=> other.instance_variable_get(ivar)
  end.reject { |c| c == 0 }
  return 0 if comparisons.empty?
  comparisons.inject(0) { |acc, each| acc + each } >= 1 ? 1 : -1
end