def METHOD_NAME(cls, unit, *, fraction=True):
    """Convert a unit to its string representation.
    Implementation for `~astropy.units.UnitBase.to_string`.
    Parameters
    ----------
    unit : |Unit|
        The unit to convert.
    fraction : {False|True|'inline'|'multiline'}, optional
        Options are as follows:
        - `False` : display unit bases with negative powers as they are
          (e.g., ``km s-1``);
        - 'inline' or `True` : use a single-line fraction (e.g., ``km / s``);
        - 'multiline' : use a multiline fraction (available for the
          ``latex``, ``console`` and ``unicode`` formats only; e.g.,
          ``$\\mathrm{\\frac{km}{s}}$``).
    Raises
    ------
    ValueError
        If ``fraction`` is not recognized.
    """
    # First the scale.  Normally unity, in which case we omit
    # it, but non-unity scale can happen, e.g., in decompositions
    # like u.Ry.decompose(), which gives "2.17987e-18 kg m2 / s2".
    if unit.scale == 1:
        s = ""
    else:
        s = cls.format_exponential_notation(unit.scale)
    # Now the unit baes, taking care that dimensionless does not have any
    # (but can have a scale; e.g., u.percent.decompose() gives "0.01").
    if len(unit.bases):
        if s:
            s += cls._scale_unit_separator
        if fraction:
            numerator, denominator = utils.get_grouped_by_powers(
                unit.bases, unit.powers
            )
        else:
            numerator = list(zip(unit.bases, unit.powers))
            denominator = []
        if len(denominator):
            if len(numerator):
                numerator = cls._format_unit_list(numerator)
            else:
                numerator = "1"
            denominator = cls._format_unit_list(denominator)
            s = cls._format_fraction(s, numerator, denominator, fraction=fraction)
        else:
            s += cls._format_unit_list(numerator)
    return s