Sha256: 0405e5ec84ef2abb2af80d063bd13b89b983f8c4f42f6b7ababff6a873b1c22c

Contents?: true

Size: 483 Bytes

Versions: 3

Compression:

Stored size: 483 Bytes

Contents

module Unitwise
  module Composable

    def self.included(base)
      base.send :include, Comparable
    end

    def composition
      root_terms.reduce(SignedMultiset.new) do |s, t|
        s.increment(t.atom.key, t.exponent) if t.atom; s
      end
    end

    def similar_to?(other)
      self.composition == other.composition
    end

    def <=>(other)
      if other.respond_to?(:composition) && similar_to?(other)
        scalar <=> other.scalar
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unitwise-0.2.1 lib/unitwise/composable.rb
unitwise-0.2.0 lib/unitwise/composable.rb
unitwise-0.1.0 lib/unitwise/composable.rb