Module: Value::Comparable
- Includes:
- Comparable
- Defined in:
- lib/value-1.0/comparable.rb
Overview
Module included by Module#Value when passed the :comparable option.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
The first non-zero comparison of the Attributes#comparable values of the receiver with those of OTHER (zero if they’re all equal), or nil if the #class of the receiver doesn’t ‘#==` that of OTHER.
Instance Method Details
#<=>(other) ⇒ Integer?
Returns The first non-zero comparison of the Attributes#comparable values of the receiver with those of OTHER (zero if they’re all equal), or nil if the #class of the receiver doesn’t ‘#==` that of OTHER.
11 12 13 14 15 |
# File 'lib/value-1.0/comparable.rb', line 11 def <=>(other) return nil unless self.class == other.class v = nil (attributes.comparable.any?{ |e| v = (send(e) <=> other.send(e)).nonzero? } and v) or 0 end |