L'Hopital's rule is a horrid thing that should be banned from introductory calculus courses because it can and is used by those who do not understand it, and the problems it is used to solve are generally better solved by other means.
This question should be asked only of students who understand the Taylor approximations of the exponential and cosine. Then, since
\begin{align*}
ae^{x} + b\cos{x} &= a( 1+ x + \text{terms quadratic in $x$}) + b(1 + \text{terms quadratic in $x$}) \\
& = a + ax + b + \text{terms quadratic in $x$}
\end{align*}
it follows that
$$\frac{ae^{x} + b\cos{x}}{x} = \frac{a+b}{x} + a + \text{terms linear in $x$}$$
and so to obtain $2$ when $x \to 0$ it must be that $b = -a$ and $a = 2$.
Of course this is not a rigorous or careful argument, but all the understanding is there.