Method: RubyUnits::Unit#===

Defined in:
lib/ruby_units/unit.rb

#===(other) ⇒ Boolean Also known as: same?, same_as?

Compare two units. Returns true if quantities and units match

Examples:

RubyUnits::Unit.new("100 cm") === RubyUnits::Unit.new("100 cm")   # => true
RubyUnits::Unit.new("100 cm") === RubyUnits::Unit.new("1 m")      # => false

Parameters:

Returns:

  • (Boolean)


681
682
683
684
685
686
687
688
689
690
691
692
693
# File 'lib/ruby_units/unit.rb', line 681

def ===(other)
  case other
    when Unit
      (self.scalar == other.scalar) && (self.units == other.units)
    else
      begin
        x, y = coerce(other)
        return x === y
      rescue ArgumentError
        return false
      end
  end
end