Sha256: 9155510c6bed39ab819f70c42b3250360d7556da8ca56ab4f67bb794aeed035f

Contents?: true

Size: 633 Bytes

Versions: 5

Compression:

Stored size: 633 Bytes

Contents

module RubyUnits
  # Extra methods for [::Array] to support conversion to [RubyUnits::Unit]
  module Array
    # Construct a unit from an array
    #
    # @example [1, 'mm'].to_unit => RubyUnits::Unit.new("1 mm")
    # @param [RubyUnits::Unit, String] other 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 Array.prepend(RubyUnits::Array) to avoid YARD warnings
# @see https://github.com/lsegal/yard/issues/1353
class Array
  prepend(RubyUnits::Array)
end

Version data entries

5 entries across 5 versions & 1 rubygems

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