Module: Unit::Comparable
- Included in:
- ComposedUnit, SimpleUnit
- Defined in:
- lib/unitmanager/simple_unit.rb
Overview
Adds comparing capabilities to unit implementations
Instance Method Summary collapse
-
#compatible?(other) ⇒ Boolean
Two units are compatible if they have same hierarchy base Example :cm is compatible with :in, since they both based on :mm.
- #contains?(other) ⇒ Boolean
Instance Method Details
#compatible?(other) ⇒ Boolean
Two units are compatible if they have same hierarchy base Example :cm is compatible with :in, since they both based on :mm
66 67 68 69 70 71 72 |
# File 'lib/unitmanager/simple_unit.rb', line 66 def compatible? (other) return false if other == nil return false unless other.respond_to?(:h_base) h_base[:dividends].same?(other.h_base[:dividends]) && h_base[:divisors].same?(other.h_base[:divisors]) end |
#contains?(other) ⇒ Boolean
74 75 76 77 78 79 80 |
# File 'lib/unitmanager/simple_unit.rb', line 74 def contains? (other) return false if other == nil return false unless other.respond_to?(:h_base) h_base[:dividends].contains?(other.h_base[:dividends]) && h_base[:divisors].contains?(other.h_base[:divisors]) end |