def to_units(*units)
      sorted_units = self.class.sort_units(units).reverse

      _, parts = sorted_units.reduce([self, {}]) do |(remainder, parts), unit|
        part = remainder.to_unit(unit)
        new_remainder = remainder - Duration.new(unit => part)

        [new_remainder, parts.merge(unit => part)]
      end

      parts
    end
def to_units(*units)
      sorted_units = self.class.sort_units(units).reverse

      _, parts = sorted_units.reduce([self, {}]) do |(remainder, parts), unit|
        part = remainder.to_unit(unit)
        new_remainder = remainder - Duration.new(unit => part)

        [new_remainder, parts.merge(unit => part)]
      end

      parts
    end
Convert the duration to a hash of units. For each given unit argument,
 the returned hash will map the unit to the quantity of that unit present
 in the duration. Each returned unit will be truncated to an integer, and
 the remainder will "carry" to the next unit down. The resulting hash can
 be passed to {Duration#initialize} to get the same result, so this method
 can be thought of as the inverse of {Duration#initialize}.

 @param [Array<Symbol>] units The units to convert to. Each unit
   will correspond with a key in the returned hash.

 @return [Hash<Symbol, Integer>] A hash mapping each unit to the quantity
   of that unit. Note that whether the returned unit is plural, or uses
   an alias, depends on what unit was passed in as an argument.

 @note The duration may be normalized or denormalized first, depending
   on the units requested. This behavior is identical to {#to_unit}.

 @example
   121.seconds.to_units(:minutes)
   # => {minutes: 2}
   121.seconds.to_units(:minutes, :seconds)
   # => {minutes: 2, seconds: 1}
   1.year.to_units(:days)
   # => {days: 365}
   (91.days 12.hours).to_units(:months, :hours)
   # => {months: 3, hours: 36}