Sha256: 3a554d1d17345fdc9f86b5e9a3b8f2cf8ebb10cb1f7749c063ed6aa48c15a763

Contents?: true

Size: 972 Bytes

Versions: 1

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

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

1 entries across 1 versions & 1 rubygems

Version Path
ruby-units-4.1.0 lib/ruby_units/numeric.rb