Sha256: a31e0cc5db8edce259c790bc2927c18a4182c914290a3cc71c18124c10750439

Contents?: true

Size: 941 Bytes

Versions: 5

Compression:

Stored size: 941 Bytes

Contents

module RubyUnits
  # Extra methods for [::Numeric] to allow it to be used as a [RubyUnits::Unit]
  module Numeric
    # Make a unitless unit with a given scalar.
    # > In ruby-units <= 2.3.2 this method would create a new [RubyUnits::Unit]
    # > with the scalar and passed in units. This was changed to be more
    # > consistent with the behavior of [#to_unit]. Specifically the argument is
    # > used as a convenience method to convert the unitless scalar unit to a
    # > compatible unitless unit.
    #
    # @param other [RubyUnits::Unit, String] convert to same units as passed
    # @return [RubyUnits::Unit]
    def to_unit(other = nil)
      other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
    end
  end
end

# @note Do this instead of Numeric.prepend(RubyUnits::Numeric) to avoid YARD warnings
# @see https://github.com/lsegal/yard/issues/1353
class Numeric
  prepend(RubyUnits::Numeric)
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-units-4.0.3 lib/ruby_units/numeric.rb
ruby-units-4.0.2 lib/ruby_units/numeric.rb
ruby-units-4.0.1 lib/ruby_units/numeric.rb
ruby-units-4.0.0 lib/ruby_units/numeric.rb
ruby-units-3.0.0 lib/ruby_units/numeric.rb