@@ -727,7 +727,8 @@ def to_s(target_units = nil, precision: 0.0001, format: RubyUnits.configuration.
727727 end
728728
729729 # Normally pretty prints the unit, but if you really want to see the guts of it, pass ':dump'
730- # @deprecated
730+ # @deprecated The dump parameter is deprecated. Use the default inspect behavior for debugging.
731+ # @param dump [Symbol, nil] pass :dump to see internal structure (deprecated)
731732 # @return [String]
732733 def inspect(dump = nil)
733734 return super() if dump
@@ -1014,8 +1015,11 @@ def %(other)
10141015 end
10151016 alias modulo %
10161017
1017- # @param [Object] other
1018- # @return [Unit]
1018+ # Divide two units and return quotient as a float or complex.
1019+ # Similar to division but ensures floating point result.
1020+ #
1021+ # @param other [Numeric, Unit]
1022+ # @return [Float, Complex, Unit]
10191023 # @raise [ZeroDivisionError] if other is zero
10201024 def quo(other)
10211025 self / other
@@ -1063,8 +1067,10 @@ def **(other)
10631067 end
10641068 end
10651069
1066- # returns the unit raised to the n-th power
1067- # @param [Integer] n
1070+ # Raise a unit to a power.
1071+ # Returns the unit raised to the n-th power.
1072+ #
1073+ # @param n [Integer] the exponent (must be an integer)
10681074 # @return [Unit]
10691075 # @raise [ArgumentError] when attempting to raise a temperature to a power
10701076 # @raise [ArgumentError] when n is not an integer
@@ -1080,8 +1086,10 @@ def power(n)
10801086 end
10811087
10821088 # Calculates the n-th root of a unit
1083- # if n < 0, returns 1/unit^(1/n)
1084- # @param [Integer] n
1089+ # Returns the nth root of a unit.
1090+ # If n < 0, returns 1/unit^(1/n)
1091+ #
1092+ # @param n [Integer] the root degree (must be an integer, cannot be 0)
10851093 # @return [Unit]
10861094 # @raise [ArgumentError] when attempting to take the root of a temperature
10871095 # @raise [ArgumentError] when n is not an integer
@@ -1267,9 +1275,9 @@ def as_json(*)
12671275
12681276 # Returns the 'unit' part of the Unit object without the scalar
12691277 #
1270- # @param with_prefix [Boolean] include prefixes in output
1271- # @param format [Symbol] Set to :exponential to force all units to be displayed in exponential format
1272- #
1278+ # @param with_prefix [Boolean] include prefixes in output (default: true)
1279+ # @param format [Symbol] Set to :exponential to force exponential notation (e.g., 'm*s^-2'),
1280+ # or :rational for rational notation (e.g., 'm/s^2'). Defaults to configuration setting.
12731281 # @return [String]
12741282 def units(with_prefix: true, format: nil)
12751283 return "" if @numerator == UNITY_ARRAY && @denominator == UNITY_ARRAY
@@ -1367,8 +1375,11 @@ def truncate(*args)
13671375 self.class.new(@scalar.truncate(*args), @numerator, @denominator)
13681376 end
13691377
1370- # returns next unit in a range. '1 mm'.to_unit.succ #=> '2 mm'.to_unit
1371- # only works when the scalar is an integer
1378+ # Returns next unit in a range. Increments the scalar by 1.
1379+ # Only works when the scalar is an integer.
1380+ # This is used primarily to make ranges work.
1381+ #
1382+ # @example '1 mm'.to_unit.succ #=> '2 mm'.to_unit
13721383 # @return [Unit]
13731384 # @raise [ArgumentError] when scalar is not equal to an integer
13741385 def succ
@@ -1379,8 +1390,11 @@ def succ
13791390
13801391 alias next succ
13811392
1382- # returns previous unit in a range. '2 mm'.to_unit.pred #=> '1 mm'.to_unit
1383- # only works when the scalar is an integer
1393+ # Returns previous unit in a range. Decrements the scalar by 1.
1394+ # Only works when the scalar is an integer.
1395+ # This is used primarily to make ranges work.
1396+ #
1397+ # @example '2 mm'.to_unit.pred #=> '1 mm'.to_unit
13841398 # @return [Unit]
13851399 # @raise [ArgumentError] when scalar is not equal to an integer
13861400 def pred
@@ -1416,13 +1430,22 @@ def zero?
14161430 end
14171431
14181432 # @example '5 min'.to_unit.ago
1419- # @return [Unit]
1433+ # Returns the time that was this duration ago from now.
1434+ # Alias for #before with default time of Time.now
1435+ #
1436+ # @example '5 min'.to_unit.ago #=> Time 5 minutes ago
1437+ # @return [Time, DateTime]
14201438 def ago
14211439 before
14221440 end
14231441
1424- # @example '5 min'.before(time)
1425- # @return [Unit]
1442+ # Returns the time that was this duration before the given time point.
1443+ #
1444+ # @example '5 min'.to_unit.before(time) #=> Time 5 minutes before time
1445+ # @example '5 min'.to_unit.before #=> Time 5 minutes ago
1446+ # @param time_point [Time, Date, DateTime] the reference time (defaults to Time.now)
1447+ # @return [Time, Date, DateTime]
1448+ # @raise [ArgumentError] when time_point is not a Time, Date, or DateTime
14261449 def before(time_point = ::Time.now)
14271450 case time_point
14281451 when Time, Date, DateTime
@@ -1506,6 +1529,10 @@ def coerce(other)
15061529 # * Units containing 'kg' will be returned as is. The prefix in 'kg' makes this an odd case.
15071530 # * It will use `centi` instead of `milli` when the scalar is between 0.01 and 0.001
15081531 #
1532+ # @example
1533+ # Unit.new('1000 m').best_prefix #=> '1 km'.to_unit
1534+ # Unit.new('0.5 m').best_prefix #=> '50 cm'.to_unit
1535+ # Unit.new('1500 W').best_prefix #=> '1.5 kW'.to_unit
15091536 # @return [Unit]
15101537 def best_prefix
15111538 return to_base if scalar.zero?
0 commit comments